Skip to content

Commit

Permalink
Make keys consistent with other options (palantir#2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMH authored and nchen63 committed Jan 23, 2017
1 parent 7751f99 commit 1e3b024
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
30 changes: 16 additions & 14 deletions src/rules/commentFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import * as Lint from "../index";
import { escapeRegExp } from "../utils";

interface IExceptionsObject {
ignoreWords?: string[];
ignorePattern?: string;
"ignore-words"?: string[];
"ignore-pattern"?: string;
}

type ExceptionsRegExp = RegExp | null;
Expand All @@ -49,8 +49,8 @@ export class Rule extends Lint.Rules.AbstractRule {
One of two options can be provided in this object:
* \`"ignoreWords"\` - array of strings - words that will be ignored at the beginning of the comment.
* \`"ignorePattern"\` - string - RegExp pattern that will be ignored at the beginning of the comment.
* \`"ignore-words"\` - array of strings - words that will be ignored at the beginning of the comment.
* \`"ignore-pattern"\` - string - RegExp pattern that will be ignored at the beginning of the comment.
`,
options: {
type: "array",
Expand All @@ -67,13 +67,13 @@ export class Rule extends Lint.Rules.AbstractRule {
{
type: "object",
properties: {
ignoreWords: {
"ignore-words": {
type: "array",
items: {
type: "string",
},
},
ignorePattern: {
"ignore-pattern": {
type: "string",
},
},
Expand All @@ -87,8 +87,8 @@ export class Rule extends Lint.Rules.AbstractRule {
},
optionExamples: [
'[true, "check-space", "check-uppercase"]',
'[true, "check-lowercase", {"ignoreWords": ["TODO", "HACK"]}]',
'[true, "check-lowercase", {"ignorePattern": "STD\\w{2,3}\\b"}]',
'[true, "check-lowercase", {"ignore-words": ["TODO", "HACK"]}]',
'[true, "check-lowercase", {"ignore-pattern": "STD\\w{2,3}\\b"}]',
],
type: "style",
typescriptOnly: false,
Expand Down Expand Up @@ -158,16 +158,18 @@ class CommentWalker extends Lint.RuleWalker {
return null;
}

if (exceptionsObject.ignorePattern) {
this.failureIgnorePart = Rule.IGNORE_PATTERN_FAILURE_FACTORY(exceptionsObject.ignorePattern);
if (exceptionsObject["ignore-pattern"]) {
const ignorePattern = exceptionsObject["ignore-pattern"] as string;
this.failureIgnorePart = Rule.IGNORE_PATTERN_FAILURE_FACTORY(ignorePattern);
// regex is "start of string"//"any amount of whitespace" followed by user provided ignore pattern
return new RegExp(`^//\\s*(${exceptionsObject.ignorePattern})`);
return new RegExp(`^//\\s*(${ignorePattern})`);
}

if (exceptionsObject.ignoreWords) {
this.failureIgnorePart = Rule.IGNORE_WORDS_FAILURE_FACTORY(exceptionsObject.ignoreWords);
if (exceptionsObject["ignore-words"]) {
const ignoreWords = exceptionsObject["ignore-words"] as string[];
this.failureIgnorePart = Rule.IGNORE_WORDS_FAILURE_FACTORY(ignoreWords);
// Converts all exceptions values to strings, trim whitespace, escapes RegExp special characters and combines into alternation
const wordsPattern = exceptionsObject.ignoreWords
const wordsPattern = ignoreWords
.map(String)
.map((str) => str.trim())
.map(escapeRegExp)
Expand Down
4 changes: 2 additions & 2 deletions test/rules/comment-format/exceptions-pattern/tslint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"rules": {
"comment-format": [true, "check-space", "check-lowercase", {"ignorePattern": "STD\\w{2,3}"}]
"comment-format": [true, "check-space", "check-lowercase", {"ignore-pattern": "STD\\w{2,3}"}]
},
"jsRules": {
"comment-format": [true, "check-uppercase", {"ignorePattern": "std(in|out|err)\\b"}]
"comment-format": [true, "check-uppercase", {"ignore-pattern": "std(in|out|err)\\b"}]
}
}
4 changes: 2 additions & 2 deletions test/rules/comment-format/exceptions-words/tslint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"rules": {
"comment-format": [true, "check-space", "check-lowercase", {"ignoreWords": ["TODO", "HACK"]}]
"comment-format": [true, "check-space", "check-lowercase", {"ignore-words": ["TODO", "HACK"]}]
},
"jsRules": {
"comment-format": [true, "check-uppercase", {"ignoreWords": ["todo"]}]
"comment-format": [true, "check-uppercase", {"ignore-words": ["todo"]}]
}
}

0 comments on commit 1e3b024

Please sign in to comment.