Running ionic-app-scripts tslint script with cli options

I have changed my package.json to include this:
"scripts": { "lint": "ionic-app-scripts lint" },

I then run npm run lint which works.

I would then like to use the --fix option for tslint to automatically fix errors. How would I do this? If I use npm run lint --fix, it just runs the script as usual.

I want to auto fix, too.

Install tslint:

npm install tslint --save-dev

And add this shortcut in the “scripts” section of package.json :

"lint": "tslint --format verbose --project tsconfig.json --config tslint.json"

Running it through script you’ll see errors that aren’t captured by the editors because they require type checking, such as no-floating-promises. Here are sample rules to put in tslint.json:

{
  "defaultSeverity": "warning",
  "extends": "tslint-ionic-rules",
  "jsRules": {},
  "rules": {
      "no-duplicate-variable": true,
      "no-floating-promises": { "severity": "error" },
      "promise-function-async": true,
      "no-unused-variable": [ true ],
      "no-var-requires": false
  },
  "rulesDirectory": [
      "node_modules/tslint-eslint-rules/dist/rules"
  ]
}

PS: to extend from those rules run:
npm instal tslint-ionic-rules --save-dev

And to fix files, just call the full command directly from terminal so you can add the --fix parameter.

3 Likes