From 11710af985b7d42e5c2c36707c08ff51cd3e6d7b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 25 Jul 2024 23:09:54 +0900 Subject: [PATCH] feat: exclude eslint-disable from commentTemplate (#2) BREAKING CHANGE: `eslint-disable` no longer required or accepted in `commentTemplate` --- README.md | 4 ++-- src/rules/fix-later/rule-meta.ts | 12 ++++-------- tests/specs/insert-disable-comment/git-blame.ts | 8 ++++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index eff8be3..0fd672e 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Whether to put the `eslint-disable` comment on the same line or on the line abov Type: string -Default: `'// {{ eslint-disable }} -- Fix later'` +Default: `'Fix later'` The template for the `eslint-disable` comment. The `{{ eslint-disable }}` handlebar is required to interpolate the `eslint-disable` type into. @@ -126,7 +126,7 @@ The template for the `eslint-disable` comment. The `{{ eslint-disable }}` handle You can also `git blame` the errorneous code and leave a TODO for the author: ``` -// {{ eslint-disable }} -- Please fix: {{ blame.author }} <{{ blame.author-mail }}> +Please fix: {{ blame.author }} <{{ blame.author-mail }}> ``` Which will create the following comment: diff --git a/src/rules/fix-later/rule-meta.ts b/src/rules/fix-later/rule-meta.ts index b8ee80e..293e82f 100644 --- a/src/rules/fix-later/rule-meta.ts +++ b/src/rules/fix-later/rule-meta.ts @@ -14,15 +14,11 @@ export const normalizeOptions = ( options: RuleOptions | undefined, ): RuleOptions => { const insertDisableComment = options?.insertDisableComment ?? 'end-of-line'; - const commentTemplate = options?.commentTemplate ?? '// {{ eslint-disable }} -- Fix later'; + const commentTemplate = options?.commentTemplate ?? 'Fix later'; - if (!commentTemplate.includes('{{ eslint-disable }}')) { - throw new Error('commentTemplate must include {{ eslint-disable }}'); - } - - if (!commentTemplate.includes('--')) { + if (!commentTemplate) { // If there is no description, then it's not discernable from other disable directives - throw new Error('commentTemplate must include a description (e.g. "// {{ eslint-disable }} -- Fix later")'); + throw new Error('commentTemplate must include a description (e.g. "Fix later")'); } return { @@ -33,7 +29,7 @@ export const normalizeOptions = ( ? 'eslint-disable-next-line' : 'eslint-disable-line' ), - commentTemplate, + commentTemplate: `// {{ eslint-disable }} -- ${commentTemplate}`, }; }; diff --git a/tests/specs/insert-disable-comment/git-blame.ts b/tests/specs/insert-disable-comment/git-blame.ts index 4b85e60..7c22ebc 100644 --- a/tests/specs/insert-disable-comment/git-blame.ts +++ b/tests/specs/insert-disable-comment/git-blame.ts @@ -19,7 +19,7 @@ export default testSuite(({ describe }, eslintPath: string) => { config: { rules: { 'fix-later/fix-later': ['error', { - commentTemplate: '// {{ eslint-disable }} -- {{ blame.author }} {{ blame.author-mail }}', + commentTemplate: '{{ blame.author }} {{ blame.author-mail }}', }], 'no-console': 'error', }, @@ -46,7 +46,7 @@ export default testSuite(({ describe }, eslintPath: string) => { config: { rules: { 'fix-later/fix-later': ['error', { - commentTemplate: '// {{ eslint-disable }} -- {{ blame.author }} {{ blame.author-mail }}', + commentTemplate: '{{ blame.author }} {{ blame.author-mail }}', }], 'no-console': 'error', }, @@ -66,7 +66,7 @@ export default testSuite(({ describe }, eslintPath: string) => { config: { rules: { 'fix-later/fix-later': ['warn', { - commentTemplate: '// {{ eslint-disable }} -- {{ blame.author }} <{{ blame.author-mail }}>', + commentTemplate: '{{ blame.author }} <{{ blame.author-mail }}>', }], 'no-console': 'error', }, @@ -92,7 +92,7 @@ export default testSuite(({ describe }, eslintPath: string) => { config: { rules: { 'fix-later/fix-later': ['warn', { - commentTemplate: '// {{ eslint-disable }} -- {{ blame.author }} <{{ blame.author-mail }}>', + commentTemplate: '{{ blame.author }} <{{ blame.author-mail }}>', }], 'no-console': 'error', },