-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
582 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
### `tag-lines` | ||
|
||
Enforces lines (or no lines) between tags. | ||
|
||
#### Options | ||
|
||
The first option is a single string set to "always" or "never" (defaults to | ||
"never"). | ||
|
||
The second option is an object with the following optional properties. | ||
|
||
##### `count` (defaults to 1) | ||
|
||
Use with "always" to indicate the number of lines to require be present. | ||
|
||
##### `noEndLine` (defaults to `false`) | ||
|
||
Use with "always" to indicate tag lines should not be added at the end. | ||
|
||
||| | ||
|---|---| | ||
|Context|everywhere| | ||
|Tags|Any| | ||
|Recommended|false| | ||
|Settings|N/A| | ||
|Options|(a string matching `"always" or "never"` and optional object with `count` and `noEndLine`)| | ||
|
||
<!-- assertions tagLines --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import iterateJsdoc from '../iterateJsdoc'; | ||
|
||
export default iterateJsdoc(({ | ||
context, | ||
jsdoc, | ||
utils, | ||
}) => { | ||
const [ | ||
alwaysNever = 'never', | ||
{ | ||
count = 1, | ||
noEndLine = false, | ||
} = {}, | ||
] = context.options; | ||
|
||
if (alwaysNever === 'never') { | ||
jsdoc.tags.some((tg, tagIdx) => { | ||
return tg.source.some(({tokens: {tag, name, type, description, end}}, idx) => { | ||
const fixer = () => { | ||
utils.removeTagItem(tagIdx, idx); | ||
}; | ||
if (!tag && !name && !type && !description && !end) { | ||
utils.reportJSDoc( | ||
'Expected no lines between tags', | ||
{line: tg.source[0].number + 1}, | ||
fixer, | ||
true, | ||
); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
(noEndLine ? jsdoc.tags.slice(0, -1) : jsdoc.tags).some((tg, tagIdx) => { | ||
const lines = []; | ||
|
||
tg.source.forEach(({number, tokens: {tag, name, type, description, end}}, idx) => { | ||
if (!tag && !name && !type && !description && !end) { | ||
lines.push({idx, number}); | ||
} | ||
}); | ||
if (lines.length < count) { | ||
const fixer = () => { | ||
utils.addLines(tagIdx, lines[lines.length - 1]?.idx || 1, count - lines.length); | ||
}; | ||
utils.reportJSDoc( | ||
`Expected ${count} line${count === 1 ? '' : 's'} between tags but found ${lines.length}`, | ||
{line: lines[lines.length - 1]?.number || tg.source[0].number}, | ||
fixer, | ||
true, | ||
); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
}, { | ||
iterateAllJsdocs: true, | ||
meta: { | ||
docs: { | ||
description: 'Enforces lines (or no lines) between tags.', | ||
url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-tag-lines', | ||
}, | ||
fixable: true, | ||
schema: [ | ||
{ | ||
enum: ['always', 'never'], | ||
type: 'string', | ||
}, | ||
{ | ||
additionalProperies: false, | ||
properties: { | ||
count: { | ||
type: 'integer', | ||
}, | ||
noEndLine: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
type: 'object', | ||
}, | ||
], | ||
type: 'suggestion', | ||
}, | ||
}); |
Oops, something went wrong.