Nx: @nrwl/linter: add support/option to builder to run lint only on touched files in affected tree

Created on 11 Sep 2020  路  6Comments  路  Source: nrwl/nx

Description + Motivation

Currently when affected is executed it runs all targets on whole affected tree, which makes 100% sense for:

  • build
  • test
  • e2e
  • type-check ( not part of standard targets but we're using it at work to run tsc)

those afformentioned targets are real safe-guards in terms of not breaking API/application

Now for lint on the other hand, we know it's not necessary ( for our monorepo project 5k + modules ).

What we can say with confidence, is, that for our use case, it would make sense, to run linter only on touched files per project in particular affected tree, thus rapidly speeding up linting process on CI.

NOTE:
you might be thinking, there is this cache option, provided by native eslint
--->
well in short, that doesn't work properly, especially on CI

Edge cases:

let's say we have this simple dep graph

// lib A uses lib B
[ lib A ]  ---> [ lib B ]
  • if one uses type aware lint rules from @typescript-eslint/no-unsafe- family and they are set to severity: error, and owner of libB changes api to return any ( which is a type information breaking change, which could be possibly catched by TypeScript anyways ), then consumer of libB (libA) would contain invalid code from linter perspective, thus introduce error to other developers after it was merged

Suggested Implementation

I'd add new option flag to current builder, to support this behaviour as an opt-in feature, which would not introduce breaking changes.

"lint": {
          "builder": "@nrwl/linter:lint",
          "options": {
            "linter": "eslint",
            "config": "path/to/lib/.eslintrc",
            "tsConfig": [
               "path/to/lib/tsconfig.lib.json",
              "path/to/lib/tsconfig.spec.json"
            ],
            "exclude": ["**/node_modules/**"],
+           "touchedOnly": true
          }
        }

with that touchedOnly could just extract touched files internaly and provide those to already supported --files flag

Alternate Implementations

linter feature

Most helpful comment

@cafesanu I'll soon release lint builder with this functionality :)

All 6 comments

@JamesHenry 馃憢 . You might want to chime in here as well 馃槃

Having the same issue. I would same the same applies to format:check and format:write... I would even go further and say that, for the format, it doesn't even depend on the graph, as there is only one .prettierrc for all apps/libs. So, a simple diff of files between base and head should do it right?

@cafesanu I'll soon release lint builder with this functionality :)

Nice! is this part of the new eslint builder in 10.3.0?

Nice! is this part of the new eslint builder in 10.3.0?

Nope, my implementation covering this proposal - we use it at work already :)

Wow this would be a great feature to have! I just tried to wrap my head around the fact, that linting is really not dependent on the affected graph, but rather on the files that were touched :thinking:

Thanks for implementing this :raised_hands:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elliotmendiola picture elliotmendiola  路  3Comments

kmkatsma picture kmkatsma  路  3Comments

markphip picture markphip  路  3Comments

jon301 picture jon301  路  3Comments

Svancara picture Svancara  路  3Comments