Skip to content

Commit

Permalink
Respect line case for ignorePattern (#2683)
Browse files Browse the repository at this point in the history
Closes #2647
  • Loading branch information
jeddy3 committed Jun 26, 2017
1 parent bcfb45f commit 395d264
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rules/max-line-length/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ a { color: pink; }
a { color: pink; }
```

### `ignorePattern: ["/regex/"]`
### `ignorePattern: "/regex/"`

Ignore any line that matches the given regex pattern, regardless of whether it is comment or not.

Given:

```js
["/^@import\\s+/"]
"/^@import\\s+/"
```

The following is *not* considered a warning regardless of line length:
Expand Down
16 changes: 16 additions & 0 deletions lib/rules/max-line-length/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,19 @@ testRule(rule, {
column: 47,
} ],
})

testRule(rule, {
ruleName,
config: [ 20, { ignorePattern: "/(Multiple:.+)|(Should:.+)/" } ],

accept: [{
code: "/*\n Multiple: lines in multiline comments\n Should: be able to be ignored\n*/",
}],

reject: [{
code: "/*\n multiple: lines in multiline comments\n Should: be able to be ignored\n*/",
message: messages.expected(20),
line: 2,
column: 38,
}],
})
6 changes: 4 additions & 2 deletions lib/rules/max-line-length/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ const rule = function (maxLength, options) {
const rawLineLength = nextNewlineIndex - match.endIndex
const lineText = rootString.slice(match.endIndex, nextNewlineIndex)

if (optionsMatches(options, "ignorePattern", lineText)) {
return
// Case sensitive ignorePattern match
if (options && options["ignorePattern"]) {
const matches = new RegExp(options["ignorePattern"].slice(1, -1)).test(lineText)
if (matches) return
}

const urlArgumentsLength = execall(/url\((.*)\)/ig, lineText).reduce((result, match) => {
Expand Down

0 comments on commit 395d264

Please sign in to comment.