jquery.d.ts compilation failed: TsLint: exceeds maximum line length
Asked Answered
R

2

3

I am using VS 2013 with version 0.95 of TypeScript, but the linter fails the TS compilation with the error:

TsLint: app.ts checked. TsLint: jquery.d.ts compilation failed: TsLint: exceeds maximum line length of 140

The jquery.d.ts file indeed has lines well over 140 in length, but I can't find the tslint config file to edit the max-line-length value.

I'm using WebEssentials 2013, I haven't installed tslint as part of a package (NPM or Nuget).

Can anyone point me in the right direction? I'm thinking it might just be easier to set up compile/linting outside of VS for now..

Thanks.

Robbegrillet answered 19/2, 2014 at 0:44 Comment(0)
P
4

I believe that the max-line-length warning is for the length of a single line, rather than for the number of lines in a file.

You can either break the long lines up to make them smaller, or simply ignore files that aren't "your code".

/* tslint:disable */
// the jquery type definition
/* tslint:enable */

or set up your own config:

-c, --config:
    The location of the configuration file that tslint will use to
    determine which rules are activated and what options to provide
    to the rules. If no option is specified, the config file named
    tslint.json is used, so long as it exists in the path.
    The format of the file is { rules: { /* rules list */ } },
    where /* rules list */ is a key: value comma-seperated list of
    rulename: rule-options pairs. Rule-options can be either a
    boolean true/false value denoting whether the rule is used or not,
    or a list [boolean, ...] where the boolean provides the same role
    as in the non-list case, and the rest of the list are options passed
    to the rule that will determine what it checks for (such as number
    of characters for the max-line-length rule, or what functions to ban
    for the ban rule).

From https://www.npmjs.org/package/tslint

Puglia answered 19/2, 2014 at 10:7 Comment(4)
Sorry, Steve, you've mis-understood my question. 1) I know it's the line length ("has lines well over 140 in length" - from above). 2) I'm not changing the jquery.d.ts file as it is a 3rd party standard created and stored on the DefinitelyTyped repo ([link]github.com/borisyankov/DefinitelyTyped). 3) it's in Visual Studio 2013 and there is no --config switch.Robbegrillet
Hi Steve, thought i'd try editing that file on Github and have started a pull request, but don't have the TS understanding to refactor a couple of the interface definitions. I'm prioritising not having to change defaults (because, why) and out-of-the-box W.E. 2013 integration.Robbegrillet
If TSLint gains traction, maybe the project would be willing to add the ignore rules to .d.ts files by default. You want TSLint to be checking your code rather than external code and definitions right?Puglia
That's a fair point. But, if there's no point checking them at all, then they should just be ignored by TSLint altogether. My guess is that you would want to know that the definition files are doing their job (providing intellisense and such in VS), but not at the cost of running linters on all external resources on every build. I'll circumvent it for now with the exclude comment: /* tslint:disable:max-line-length */. Could you update your answer to include it (as a VS-centric solution) and I'll give you the nod? Thanks.Robbegrillet
E
6

You can modify the tslint configuration file to change the maximum line length threshold. It uses a hierarchical configuration system so you can scope the change depending on where you create/modify the tslint.conf file.

By default, configuration is loaded from tslint.json, if it exists in the current path, or the user's home directory, in that order. (source...)

On my windows computer the global configuration file was located in C:\Users\My.Username and changes here will apply to all projects. Creating or modifying the file in the root of the Visual Studio will mean the configuration settings will only apply to that project and will override the global configuration file.

The specific configuration option you need to modify for the maximum line-length is called max-line-length and would look something like this:

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

Change the 140 value to extend the allowed length of lines or change true to false to disable the max line length rule.


Alternatively, you can do what Steve has suggested in the other answer but you don't need to completely disable tslint because you can disable specific rules. The syntax for that is:

/*tslint:disable:rule1 rule2 rule3*/

So you would use:

/*tslint:disable:max-line-length*/

to disable the max-line-length rule for that file.

All of the configuration options and the rule-specific disabling are explained fully on the tslint website.

Equal answered 17/12, 2014 at 3:43 Comment(0)
P
4

I believe that the max-line-length warning is for the length of a single line, rather than for the number of lines in a file.

You can either break the long lines up to make them smaller, or simply ignore files that aren't "your code".

/* tslint:disable */
// the jquery type definition
/* tslint:enable */

or set up your own config:

-c, --config:
    The location of the configuration file that tslint will use to
    determine which rules are activated and what options to provide
    to the rules. If no option is specified, the config file named
    tslint.json is used, so long as it exists in the path.
    The format of the file is { rules: { /* rules list */ } },
    where /* rules list */ is a key: value comma-seperated list of
    rulename: rule-options pairs. Rule-options can be either a
    boolean true/false value denoting whether the rule is used or not,
    or a list [boolean, ...] where the boolean provides the same role
    as in the non-list case, and the rest of the list are options passed
    to the rule that will determine what it checks for (such as number
    of characters for the max-line-length rule, or what functions to ban
    for the ban rule).

From https://www.npmjs.org/package/tslint

Puglia answered 19/2, 2014 at 10:7 Comment(4)
Sorry, Steve, you've mis-understood my question. 1) I know it's the line length ("has lines well over 140 in length" - from above). 2) I'm not changing the jquery.d.ts file as it is a 3rd party standard created and stored on the DefinitelyTyped repo ([link]github.com/borisyankov/DefinitelyTyped). 3) it's in Visual Studio 2013 and there is no --config switch.Robbegrillet
Hi Steve, thought i'd try editing that file on Github and have started a pull request, but don't have the TS understanding to refactor a couple of the interface definitions. I'm prioritising not having to change defaults (because, why) and out-of-the-box W.E. 2013 integration.Robbegrillet
If TSLint gains traction, maybe the project would be willing to add the ignore rules to .d.ts files by default. You want TSLint to be checking your code rather than external code and definitions right?Puglia
That's a fair point. But, if there's no point checking them at all, then they should just be ignored by TSLint altogether. My guess is that you would want to know that the definition files are doing their job (providing intellisense and such in VS), but not at the cost of running linters on all external resources on every build. I'll circumvent it for now with the exclude comment: /* tslint:disable:max-line-length */. Could you update your answer to include it (as a VS-centric solution) and I'll give you the nod? Thanks.Robbegrillet

© 2022 - 2024 — McMap. All rights reserved.