nx: nx lint does not accept --files option

Expected Behavior

According documentation nx lint should accept --files array like

nx lint --files=apps/main-app/src/main.tsx

Current Behavior

Command fails to parse --files=apps/main-app/src/main.tsx

Failure Information (for bugs)

Schema validation failed with the following errors:
  Data path ".files" should be array.

Steps to Reproduce

No special preparations required. Just run command in nx workspace.

yarn nx lint --files=apps/main-app/src/main.tsx

Context

$ nx report

>  NX  Report complete - copy this into the issue template

  @nrwl/angular : Not Found
  @nrwl/cli : 8.11.0
  @nrwl/cypress : 8.11.0
  @nrwl/eslint-plugin-nx : 8.11.0
  @nrwl/express : Not Found
  @nrwl/jest : 8.11.0
  @nrwl/linter : 8.11.0
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : 8.11.0
  @nrwl/schematics : Not Found
  @nrwl/tao : 8.11.0
  @nrwl/web : 8.11.0
  @nrwl/workspace : 8.11.0
  typescript : 3.7.3

Other

packages/tao/src/shared/params.ts#coerceTypes does not check for arrays

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 25 (4 by maintainers)

Most upvoted comments

@vsavkin this issue still exists, any way we can re-open?

@vsavkin any updates on this? really need this for lint-staged.

Same issue here

>  NX  Report complete - copy this into the issue template

  @nrwl/angular : Not Found
  @nrwl/cli : 9.1.1
  @nrwl/cypress : 9.1.1
  @nrwl/eslint-plugin-nx : 9.1.1
  @nrwl/express : Not Found
  @nrwl/jest : 9.1.1
  @nrwl/linter : 9.2.3
  @nrwl/nest : 9.1.1
  @nrwl/next : 9.1.1
  @nrwl/node : 9.1.1
  @nrwl/react : 9.1.1
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.1.1
  @nrwl/web : 9.1.1  
  @nrwl/workspace : 9.1.1
  typescript : 3.8.3

Working on Nx 11.1.5 and no change here. Option “–files” still does not work. Also suggestion from @Hotell doesn’t work: nx lint my-project --files=**/some-folder/**

@vsavkin any updates on this? really need this for lint-staged.

I am unable to use raw library as @Hotell mentioned, since all libraries don’t have the same tslint configuration.

So I’ve came up with following solution:

As mentioned in documentation, you can use custom lint function. So I created a script that works like this:

First, load angular.json file, parse it (it’s super easy since it’s just a json) and store all projects with configured lint tasks (path to lint task in json structure is /projects/*your-project*/architect/lint) in a variable.

Then I try to assign staged files to their projects. It’s also easy, because each project has root path (is /projects/*your-project*/root path in json). So I go through all staged files and check that file path starts with any project root path.

After this part, I have array of projects with (staged) files that belongs to these projects.

For each project, I create command ./node_modules/@angular/cli/bin/ng run *your-project*:lint --files libs/*your-project*/src/lib/a.ts --files libs/*your-project*/src/lib/b.ts --files libs/*your-project*/src/lib/c.ts

And finally, I use concurrently to run all these lint commands together.


I know, that isn’t ideal nor easy solution, but it’s the only way I’ve found, how to get lint-staged work with multiple projects without linting all files.