Skip to content

Commit

Permalink
feat: exclude eslint-disable from commentTemplate (#2)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `eslint-disable` no longer required or accepted in `commentTemplate`
  • Loading branch information
privatenumber committed Jul 25, 2024
1 parent 11fbf27 commit 11710af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ 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.

#### Git blame

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:
Expand Down
12 changes: 4 additions & 8 deletions src/rules/fix-later/rule-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,7 +29,7 @@ export const normalizeOptions = (
? 'eslint-disable-next-line'
: 'eslint-disable-line'
),
commentTemplate,
commentTemplate: `// {{ eslint-disable }} -- ${commentTemplate}`,
};
};

Expand Down
8 changes: 4 additions & 4 deletions tests/specs/insert-disable-comment/git-blame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand Down

0 comments on commit 11710af

Please sign in to comment.