Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with ESLint "max-len" ignore pattern

I'm trying to ignore import statements with the ESLint "max-len" rule and some ES6 code. My rule set is written in a config in index.js and the config for the rule itself looks like this:

    'max-len': [
        2,
        80,
        4,
        {
            ignoreUrls: true,
            ignorePattern: /^import\s.+\sfrom\s.+;$/
        }
    ],

Lines exceeding 80 characters still trigger errors given the RegExp I've provided. Is there something I'm not understanding about the rule itself?

I've also tried simpler RegExps and passing RegExp strings such as:

'^import.*'

Found here: http://eslint.org/docs/rules/max-len

like image 651
BTC Avatar asked Feb 23 '16 01:02

BTC


People also ask

How do you set Max Len on Eslint?

This rule has a number or object option: "code" (default 80 ) enforces a maximum line length. "tabWidth" (default 4 ) specifies the character width for tab characters. "comments" enforces a maximum line length for comments; defaults to value of code.


2 Answers

I was having trouble with this as well, but @loganfsmyth's suggestion worked for me. I'm using v3.14.0 and all my rules are in an .eslintrc file:

{
  ...
  "rules": {
    "max-len": [1, 80, 2, {
      "ignorePattern": "^import\\s.+\\sfrom\\s.+;$",
      "ignoreUrls": true
    }],
    ...
  },
}
like image 162
ericgio Avatar answered Oct 27 '22 14:10

ericgio


Similar to loganfsmyth's comment and ericgio's answer, but without double-escaping, this worked for me with yaml:

rules:
  ...
  max-len:
  - error
  - code: 80
    tabWidth: 2
    ignorePattern: ^import\s.+\sfrom\s.+;$
  ...
like image 41
Mikal Madsen Avatar answered Oct 27 '22 14:10

Mikal Madsen