pinterest / arcanist-linters

A collection of custom Arcanist linters
Apache License 2.0
63 stars 45 forks source link

Pass working directory so ESLint can find plugins #78

Closed RainNapper closed 3 years ago

RainNapper commented 3 years ago

Directory structure:

/Users/mmark/code/my-repo
|-- .arclint
|-- client
    |-- node_modules
    |-- .eslintrc
|-- server
    |-- node_modules
    |-- .eslintrc

Before the change:

$ './client/node_modules/.bin/eslint' '--format=json' '--no-color' '--config' './client/.eslintrc' '--fix ' '/Users/mmark/code/my-repo/client/src/index.js'

Oops! Something went wrong! :(

ESLint: 6.8.0.

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/Users/mmark/code/my-repo".)

After the change:

$ './client/node_modules/.bin/eslint' '--format=json' '--no-color' '--config' './client/.eslintrc' '--fix ' '/Users/mmark/code/metro/client/src/index.js' '--resolve-plugins-relative-to' './client'

[successful output]

Using .arclint entry:

    "client-eslint": {
      "type": "eslint",
      "include": "(client/.*\\.js$)",
      "bin": "./client/node_modules/.bin/eslint",
      "eslint.config": "./client/.eslintrc",
      "eslint.fix": true,
      "eslint.cwd": "./client"
    }
RainNapper commented 3 years ago

PR has been updated to include a few changes: 1) New flag is removed, and now using $cwd as set in parent class. 2) Opted not to use getNodeCwd() because this function always returns something, regardless if the field is set or not. This means we would be adding the flag to every call. While this may have been okay, opted to only include flag when eslint.cwd to avoid changing behavior on old configurations.