Search code examples
tslintng-zorro-antd

NG-ANTD nz-tslint-rules migration not working


I was trying to update our production project which holds 500+ modules and we certainly need this tool to make it work because manually doing so would be a nightmare. I've been the whole afternoon trying to make it work even copying and pasting your import example and haven't manage to do so.

Our imports are like following in the whole project:

import {
  NzTableModule,
  NzCheckboxModule,
  NzInputModule,
  NzFormModule,
  NzSelectModule,
  NzDrawerModule,
  NzDividerModule,
  NzToolTipModule,
  NzDatePickerModule,
} from 'ng-zorro-antd';

I'm using the following config:

{
  "rulesDirectory": [
    "nz-tslint-rules"
  ],
  "rules": {
    "nz-secondary-entry-imports": true
  }
}

package.json:

"ng-zorro-antd": "^9.3.0", "typescript": "~3.8.3", "nz-tslint-rules": "^0.901.2", "@angular/core": "~9.1.12",

I'm executing the following command from the app root: "tslint --project ."

I've managed to be sure about the script execution with a console log in the nzSecondaryEntryImportsRule.js file

image

Also I've notice that:

tsutils.isImportDeclaration(node) Always returns false therefore it continues to the next iteration in the for loop

enter image description here

I'd appreciate any help on this.


Solution

  • I guess because the global version is too low.

    here are three solutions:

    1. upgrade your global tslint

    npm install tslint -g

    1. add the command to the scripts in package.json, and then use npm run lint:fix
    {
      "scripts": {
        "lint:fix": "tslint --project tsconfig.json --fix"
      }
    } 
    
    1. run from node_modules/.bin/tslint

    node_modules/.bin/tslint --project tsconfig.json --fix