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

Adds ignorePattern option to max-line-length #2333

Merged
merged 5 commits into from Feb 16, 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
16 changes: 16 additions & 0 deletions lib/rules/max-line-length/README.md
Expand Up @@ -108,3 +108,19 @@ a { color: pink; }
*/
a { color: pink; }
```

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

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

Given:

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

The following is *not* considered a warning regardless of line length:

```css
@import "../../../../another/css/or/scss/file/or/something.css";
```
31 changes: 31 additions & 0 deletions lib/rules/max-line-length/__tests__/index.js
Expand Up @@ -207,3 +207,34 @@ testRule(rule, {
column: 55,
} ],
})

testRule(rule, {
ruleName,
config: [ 30, { ignorePattern: "/^my-/" } ],

accept: [{
code: "my-property: has-a-really-long-declaration-value-for-some-reason",
}],

})

testRule(rule, {
ruleName,
config: [ 30, { ignorePattern: "/@import\\s+/" } ],

accept: [{
code: "@import \"../../../something/something/something/something.css\" screen, projection, tv;",
}],

reject: [ {
code: "a { color: 0;\n top: 0; left: 0; right: 0; background: pink; \n bottom: 0; }",
message: messages.expected(30),
line: 2,
column: 47,
}, {
code: "@import \"../../../something/something/something/something.css\";\na { color: 0;\n top: 0; left: 0; right: 0; background: pink; \n bottom: 0; }",
message: messages.expected(30),
line: 3,
column: 47,
} ],
})
5 changes: 5 additions & 0 deletions lib/rules/max-line-length/index.js
Expand Up @@ -26,6 +26,7 @@ const rule = function (maxLength, options) {
"non-comments",
"comments",
],
ignorePattern: [_.isString],
},
optional: true,
})
Expand Down Expand Up @@ -68,6 +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
}

const urlArgumentsLength = execall(/url\((.*)\)/ig, lineText).reduce((result, match) => {
return result + _.get(match, "sub[0].length", 0)
}, 0)
Expand Down