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)
@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
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/**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.jsonfile, 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*/rootpath 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.tsAnd 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.
Fixed it here: https://github.com/nrwl/nx/commit/a6220f7b0a677dbceb72bc2434cfeac6e4f86061
Should be out in 9.4.