I'm using the Angular starter kit
and I'm trying to get tslint to autofix all my lint problems with the --fix flag.
I'm running the script:
npm run tslint --fix src/**/*.ts
It just generates the same error that I'm already being told about in tslint
and not autofixing it:
console output:
ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from'
Am I missing something that allows it to implement the changes?
My versions are:
"tslint": "^5.6.0"
"codelyzer": "^3.1.2"
Question: How can I get tslint to implement autofix to my lint errors?
Using the command ng lint --fix is correct and should fix the indentation.
You can use the TSLint code verification tool from inside WebStorm and check your TypeScript code for most common mistakes without running the application. When the tool is activated, it lints all the opened TypeScript files and marks the detected problems.
Linting is the process of running a program that analyses your code for programmatic and stylistic errors. A Linting tool, or a linter, checks any potential errors in your code such as syntax errors, incorrectly spelled variable names, and many more. This can save time and help you write better code.
Unfortunately, not all linting violations are auto-fixable. You can see which rules are auto-fixable here by looking for the Has Fixer
tag.
My guess is that "comment must start with a space" is governed by the comment-format
rule, which is not auto-fixable.
I'm not sure which rule is causing your second error, but it is most likely also not auto-fixable.
Here's a snippet you can run tslint --fix
against to verify that some violations are fixed, and others are not.
//no var keyword (comment does not start with space)
var x: string = 'x';
console.log(x);
// array-type
let y: String[] = [];
console.log(y);
// ban-single-arg-parens
['1', '2'].filter((arg) => {
console.log(arg);
});
// semicolon
let z: string = ''
console.log(z);
// no unused variable
let a: string = '';
// trailing comma
let list = ['1', '2', ];
// missing trailing comma
let obj = [
1,
2
];
Rules to include when linting the above file:
"semicolon": [true, "always"],
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}],
"array-type": [true, "array-generic"],
"arrow-parens": [true, "ban-single-arg-parens"],
It's tempting to think that all whitespace errors would be auto-fixable, and perhaps they should be. Sadly, they're not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With