-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
66 additions
and
0 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,29 @@ | ||
'use strict'; | ||
|
||
module.exports = function(context) { | ||
return { | ||
VariableDeclaration: function(node) { | ||
if (node.kind !== 'const') { | ||
return; | ||
} | ||
|
||
if (node.parent && node.parent.type === 'Program') { | ||
// Declaration is in root of module. | ||
return; | ||
} | ||
|
||
if (node.parent && node.parent.type === 'ExportNamedDeclaration' && | ||
node.parent.parent && node.parent.parent.type === 'Program') { | ||
// Declaration is a `export const foo = 'asdf'` in root of the module. | ||
return; | ||
} | ||
|
||
context.report({ | ||
node: node, | ||
message: '`const` should only be used in module scope (not inside functions/blocks).' | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = []; // no options |
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,34 @@ | ||
'use strict'; | ||
|
||
function isDocComment(comment) { | ||
return comment.value[0] === '*'; | ||
} | ||
|
||
function isModuleOnlyComment(comment) { | ||
return comment.value.match(/^\*\n\s*@module.+\n(?:\s*@submodule.+\n)?$/); | ||
} | ||
|
||
function includesAccessDeclaration(comment) { | ||
return comment.value.match(/\n\s*(@private|@public|@protected)\s/); | ||
} | ||
|
||
module.exports = function(context) { | ||
|
||
var sourceCode = context.getSourceCode(); | ||
|
||
sourceCode.getAllComments().forEach(function(comment) { | ||
if (comment.type !== 'Block') { return; } | ||
if (!isDocComment(comment)) { return; } | ||
if (isModuleOnlyComment(comment)) { return; } | ||
if (includesAccessDeclaration(comment)) { return; } | ||
|
||
context.report({ | ||
loc: comment.loc.start, | ||
message: 'Access declaration missing, you must supply `@public`, `@private`, or `@protected` for doc comments.' | ||
}); | ||
}); | ||
|
||
return {}; | ||
}; | ||
|
||
module.exports.schema = []; // no options |