Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: deprecate applyDefaultPatterns in line-comment-position #8183

Merged
merged 1 commit into from Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/rules/line-comment-position.md
Expand Up @@ -77,24 +77,26 @@ Examples of **incorrect** code for the `ignorePattern` option:
1 + 1; // invalid comment
```

### applyDefaultPatterns
### applyDefaultIgnorePatterns

Default ignore patterns are applied even when `ignorePattern` is provided. If you want to omit default patterns, set this option to `false`.

Examples of **correct** code for the `{ "applyDefaultPatterns": false }` option:
Examples of **correct** code for the `{ "applyDefaultIgnorePatterns": false }` option:

```js
/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultPatterns": false }]*/
/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
1 + 1; // pragma valid comment
```

Examples of **incorrect** code for the `{ "applyDefaultPatterns": false }` option:
Examples of **incorrect** code for the `{ "applyDefaultIgnorePatterns": false }` option:

```js
/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultPatterns": false }]*/
/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
1 + 1; // falls through
```

**Deprecated:** the object property `applyDefaultPatterns` is deprecated. Please use the property `applyDefaultIgnorePatterns` instead.

## When Not To Use It

If you aren't concerned about having different line comment styles, then you can turn off this rule.
Expand Down
14 changes: 11 additions & 3 deletions lib/rules/line-comment-position.js
Expand Up @@ -35,6 +35,9 @@ module.exports = {
},
applyDefaultPatterns: {
type: "boolean"
},
applyDefaultIgnorePatterns: {
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -49,15 +52,20 @@ module.exports = {

let above,
ignorePattern,
applyDefaultPatterns = true;
applyDefaultIgnorePatterns = true;

if (!options || typeof options === "string") {
above = !options || options === "above";

} else {
above = options.position === "above";
ignorePattern = options.ignorePattern;
applyDefaultPatterns = options.applyDefaultPatterns !== false;

if (options.hasOwnProperty("applyDefaultIgnorePatterns")) {
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
} else {
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
}
}

const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
Expand All @@ -71,7 +79,7 @@ module.exports = {

return {
LineComment(node) {
if (applyDefaultPatterns && (defaultIgnoreRegExp.test(node.value) || fallThroughRegExp.test(node.value))) {
if (applyDefaultIgnorePatterns && (defaultIgnoreRegExp.test(node.value) || fallThroughRegExp.test(node.value))) {
return;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/line-comment-position.js
Expand Up @@ -99,6 +99,16 @@ ruleTester.run("line-comment-position", rule, {
}]
},
{
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultIgnorePatterns: false }],
errors: [{
message: "Expected comment to be beside code.",
type: "Line",
line: 1,
column: 1
}]
},
{ // deprecated option still works
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultPatterns: false }],
errors: [{
Expand All @@ -108,6 +118,16 @@ ruleTester.run("line-comment-position", rule, {
column: 1
}]
},
{ // new option name takes precedence
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultIgnorePatterns: false, applyDefaultPatterns: true }],
errors: [{
message: "Expected comment to be beside code.",
type: "Line",
line: 1,
column: 1
}]
},
{
code: "1 + 1; // mentioning falls through",
errors: [{
Expand Down