Tslint: [Bug] max-line-length - Cannot create property 'ignorePattern' on boolean 'true'

Created on 11 Jan 2018  ยท  8Comments  ยท  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.6.2
  • __Running TSLint via__: CLI

TypeScript code being linted

// for example
// ... (two tabs in front)
        const margin: { top: number, right: number, bottom: number, left: number } = { top: 20, right: 90, bottom: 60, left: 50 };
// ... line is 131 long

with tslint.json configuration:

{
    "defaultSeverity": "error",
    "extends": ["tslint:recommended"],
    "rules": {
        "max-line-length": {
            "options": [true, 120],
            "severity": "warn"
        }
    }
}

Actual behavior

$ .\node_modules\.bin\tslint --project tsconfig.json --force --format stylish
TypeError: Cannot create property 'ignorePattern' on boolean 'true'
    at Rule.getRuleOptions (<path>\node_modules\tslint\lib\rules\maxLineLengthRule.js:47:35)
    at Rule.isEnabled (<path>\node_modules\tslint\lib\rules\maxLineLengthRule.js:32:26)
    at Object.loadRules (<path>\node_modules\tslint\lib\ruleLoader.js:47:22)
    at Linter.getEnabledRules (<path>\node_modules\tslint\lib\linter.js:215:29)
    at Linter.lint (<path>\node_modules\tslint\lib\linter.js:98:33)
    at <path>\node_modules\tslint\lib\runner.js:206:32
    at step (<path>\node_modules\tslib\tslib.js:131:27)
    at Object.next (<path>\node_modules\tslib\tslib.js:112:57)
    at <path>\node_modules\tslib\tslib.js:105:75
    at new Promise (<anonymous>)

Expected behavior

$ .\node_modules\.bin\tslint --project tsconfig.json --force --format stylish
WARNING: 92:1   max-line-length           Exceeds maximum line length of 120
Formatting rule Bug Question ๐ŸŒน R.I.P. ๐ŸŒน

Most helpful comment

Working: no array

"max-line-length": {
    "options": { "limit": 120 },
    "severity": "warn"
}

The documentation really needs some more love
https://palantir.github.io/tslint/rules/max-line-length/

All 8 comments

Working: no array

"max-line-length": {
    "options": { "limit": 120 },
    "severity": "warn"
}

The documentation really needs some more love
https://palantir.github.io/tslint/rules/max-line-length/

Yeah, sorry about the docs, most of them still refer to the old options syntax (which we support for legacy reasons) which doesn't use the options: {} object syntax.

"max-line-length": [true, 120]

is equivalent to

"max-line-length": { "options": [120] }

and the rule _also_ happens to support

"max-line-length": { "options": { "limit": 120 } }

this last syntax is the recommended one.

I personly find the old legacy syntax ugly and horrible and I'm happy with the new { options, severity } syntax.
But I also dislike the array [true, ...string] syntax.

So two things:

  1. The 5.9.0 brought a breaking change for this rule, because "max-line-length": [true, 120] is not working anymore.
  2. Think about to radically kill the legacy syntax in release 6.0

Your original post shows your configuration as "max-line-length": { "options": [true, 120] }.

Are you sure it's "max-line-length": [true, 120] that's not working? If so, yeah that's a regression and we'll fix it in 5.9.x

My config with 5.8.0 was:

"max-line-length": { "severity": "warn" }

That worked with 5.8, but not with 5.9 (checked just now)

// 5.9
"max-line-length": { "options": [true, 120], "severity": "warn" } // Not working (consistent to old legacy syntax)
"max-line-length": [true, 120] // Working (consistent to old legacy syntax)
"max-line-length": { "options": [true, { "limit": 120 }], "severity": "warn" } // Not working (consistent to old legacy syntax)
"max-line-length": { "options": { "limit": 120 }, "severity": "warn" } // Working

"max-line-length": { "options": 120, "severity": "warn" } // Working

Edit: I tested the 4 (+1) versions now also with 5.8

// 5.8
"max-line-length": { "options": [true, 120], "severity": "warn" } // Can be executed, producess wrong result
"max-line-length": [true, 120] // Working (this was the old correct way)
"max-line-length": { "options": [true, { "limit": 120 }], "severity": "warn" } // Can be executed, producess wrong result
"max-line-length": { "options": { "limit": 120 }, "severity": "warn" } // Can be executed, but no output in terminal

"max-line-length": { "options": 120, "severity": "warn" } // Working

So this results into that the first and third never worked... ok
Also the 5th config I found out about is working with 5.8 and 5.9
The 4th isn't working correctly in 5.8 because it doesn't show up any warnings

For the changelog, I think, there should be added that if you havn't defined the options for this rule, you have to add it in 5.9
from:
"max-line-length": { "severity": "warn" }
to:
"max-line-length": { "options": 120, "severity": "warn" } or "max-line-length": { "options": { "limit": 120 }, "severity": "warn" }

maybe issue can be closed now :)

I had the same error, upgrading from 5.8.0 to 5.9.1 caused an error in this circleci build:

$ tslint --project ./tsconfig.json 'src/**/*.{ts,tsx}' 
TypeError: Cannot read property 'ignore-pattern' of undefined
    at Rule.getRuleOptions (/home/circleci/repo/node_modules/tslint/lib/rules/maxLineLengthRule.js:46:41)
    at Rule.isEnabled (/home/circleci/repo/node_modules/tslint/lib/rules/maxLineLengthRule.js:32:26)
    at Object.loadRules (/home/circleci/repo/node_modules/tslint/lib/ruleLoader.js:47:22)
    at Linter.getEnabledRules (/home/circleci/repo/node_modules/tslint/lib/linter.js:215:29)
    at Linter.lint (/home/circleci/repo/node_modules/tslint/lib/linter.js:98:33)
    at /home/circleci/repo/node_modules/tslint/lib/runner.js:206:32
    at step (/home/circleci/repo/node_modules/tslib/tslib.js:131:27)
    at Object.next (/home/circleci/repo/node_modules/tslib/tslib.js:112:57)
    at /home/circleci/repo/node_modules/tslib/tslib.js:105:75
    at Object.__awaiter (/home/circleci/repo/node_modules/tslib/tslib.js:101:16)
error Command failed with exit code 1.
error Command failed with exit code 1.
Exited with code 1

Adding severity to the rule like @Shinigami92 said fixed it.

โ˜ ๏ธ TSLint's time has come! โ˜ ๏ธ

TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. โœจ

It was a pleasure open sourcing with you all!

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ _(#4534)_ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings