-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,31 @@ | ||
const create = function (context) { | ||
const sourceCode = context.getSourceCode() | ||
//TODO: use getCommentsInside() | ||
const comments = sourceCode.getAllComments() | ||
|
||
return { | ||
'Program': node => { //'*' | ||
//TODO: option | ||
if (comments.length >= 10) { | ||
context.report({ | ||
node: comments[0], | ||
message: 'too many comments in this file with {{ nbComments }} comments', | ||
// eslint-disable-next-line id-blacklist | ||
data: { | ||
nbComments: comments.length | ||
} | ||
}) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
module.exports = { | ||
create, | ||
meta: { | ||
// type: 'suggestion', | ||
docs: { | ||
description: "" | ||
}, | ||
} | ||
} |
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,32 @@ | ||
var rule = require("../../../lib/rules/too-many-comments") | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const ruleTester = new RuleTester() | ||
ruleTester.run('too-many-comments', rule, { | ||
valid: [ | ||
{code: 'var simple = /ab/;'}, | ||
{code: '// a simple comment'}, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: `// comment one | ||
// comment two | ||
// comment ... | ||
// comment .... | ||
// comment ..... | ||
// comment ...... | ||
// comment ....... | ||
// comment ........ | ||
// comment ......... | ||
// comment .......... | ||
// comment .......... . | ||
// comment .......... .. | ||
// comment .......... ... | ||
`, | ||
errors: [{ | ||
message: 'too many comments in this file with 13 comments', | ||
}], | ||
}, | ||
] | ||
}) |