Skip to content

Commit

Permalink
new rule: too-many-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu1400 committed Jun 11, 2019
1 parent 98f218e commit ce0cc8c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Empty file added docs/rules/too-many-comments.md
Empty file.
31 changes: 31 additions & 0 deletions lib/rules/too-many-comments.js
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: ""
},
}
}
32 changes: 32 additions & 0 deletions tests/lib/rules/too-many-comments.js
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',
}],
},
]
})

0 comments on commit ce0cc8c

Please sign in to comment.