buzinas/tslint-eslint-rules

[ter-max-len] + ignoreStrings

Ky6uk opened this issue · 1 comments

Ky6uk commented

ignoreStrings: true does match code below like a string and ignores length check

function (param1: string, param2: number, param3: InterfaceName["prop"]) {
//                                                ^^^^^^^^^^^^^^^^^^^^^
//                                                this part detected like a string
}

That is correct and unfortunately that is what the ESlint docs say:

"ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string

I'm surprised no one has said anything about lines like you mentioned (without typescript)

function foo(param1: string, param2: number, param3: InterfaceName["prop"]) {
  const bar = fnCall(param3['doNotIgnoreMe'], param4["a"], param4[`b`], param4['c']);
}

The function call should be split but instead it is being ignored if we have the ignoreStrings or the the ignoreTemplateLiterals options.

It almost seems as if we need more a bit more control over strings. I was going to suggest to allow ignoreStrings to take in an object with exceptions:

ignoreStrings: {
  exceptPropertyAccess: true,
}

I think this would cover the example above, but then people would have issues with

const a = someElement['with-some-super-random-loooooooooooonnnnnnnnnggggggg-key-that-they-want-to-be-able-to-ignore'];

but this would be fixed by doing:

const key = 'with-some-super-random-loooooooooooonnnnnnnnnggggggg-key-that-they-want-to-be-able-to-ignore';
const a = someElement[key];

I actually want something like this even if eslint does not cover it. Can you think of other case scenarios where we would want to create exceptions to the ignore rules?