Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint: config file resolution / multiple config files #1706

Open
buschtoens opened this issue Apr 15, 2019 · 9 comments
Open

eslint: config file resolution / multiple config files #1706

buschtoens opened this issue Apr 15, 2019 · 9 comments

Comments

@buschtoens
Copy link

Hound currently only supports specifying single ESLint config file to be used for the whole repository. Unfortunately this does not play nicely with monorepos or repositories with different types of JS source files that have different linting requirements.

Quoting from the ESLint docs:

The first way to use configuration files is via .eslintrc.* and package.json files. ESLint will automatically look for them in the directory of the file to be linted, and in successive parent directories all the way up to the root directory of the filesystem (unless root: true is specified). This option is useful when you want different configurations for different parts of a project or when you want others to be able to use ESLint directly without needing to remember to pass in the configuration file.

It would be great, if Hound could support / use the same resolution logic for ESLint projects. Instead of specifying the config file explicitly, you would just specify the files / directories to be linted and let ESLint handle the config resolution.

This repo describes why you would want to use different ESLint configs in the same repo: @clark/eslint-config-ember

Thank you for considering!

@TomasBarry
Copy link
Contributor

Is there any possibility of getting this functionality? It is becoming a blocker for our continued usage of Hound which we really like.

@gylaz
Copy link
Member

gylaz commented Jul 10, 2019

@TomasBarry Could you describe how you are using multiple configuration files?

As described in the OP, it's not likely to be supported as "Instead of specifying the config file explicitly, you would just specify the files / directories to be linted" because that's just not how Hound works, and we need to preserve the behavior for all the current users.

One possible solution for multiple configs could be something like:

eslint:
  enabled: true
  config_files:
    - .eslintrc
    - .prettierrc
    - test/.eslintrc

Where the first two files would be placed at the root, and the last tested in test/ when a file like test/foo/bar.js. Would something like that fit your use case?

@TomasBarry
Copy link
Contributor

TomasBarry commented Jul 10, 2019

@gylaz, an exaggeration of our scenario would be a directory structure such as:

foo/
--bar/
----bar.js
----.eslintrc.json
--baz/
----baz.js
----.eslintrc.json
--foo.js
--.eslintrc.json

Where all 3 eslintrc.json files have conflicting rules (let's say the top-level .eslintrc.json files requires semicolons but the .eslintrc.json files in bar/ and baz/ don't) therefore Hound should use a different .eslintrc.json file depending on what file it is linting.

So if a change is made to foo.js, it should use the top-level .eslintrc.json file (and require semicolons, for example), but a change to bar.js should use the foo/bar/.eslintrc.json configuration (and not allow semicolons, for example.

Does that make sense?

I believe your suggestion would suit our needs - files in a directory are linted under the rules outlined by the .eslintrc.json file for that directory (and if Hound needs to be given the path to each .eslintrc.json file, that is fine too so long as it uses the appropriate .eslintrc.json file when linting).

@buschtoens
Copy link
Author

In the example you provided, foo/.eslintrc.json would by default be applicable to foo/bar/bar.js and foo/baz/baz.js. Only, if foo/bar/.eslintrc.json and foo/baz/ .eslintrc.json specify root: true, foo/.eslintrc.json would not apply to them.

Assuming, foo/bar/.eslintrc.json and foo/baz/.eslintrc.json do specify root: true, would Hound be smart enough to understand that foo/.eslintrc.json should not lint the foo/bar and foo/baz directories?

@TomasBarry
Copy link
Contributor

You are correct, I gave a bad example. Basically, we are following the instructions here to have a root set of rules and then extra rules based on the given directory.

But Hound is only running the code against the root set of rules.

Our specific example is that the root .eslintrc.json file does not require a comma dangle, but one of our subdirectories has a .eslintrc.json file that does ("comma-dangle": ["error", "always-multiline"],).

So we have a file, in the subdirectory that should require a comma dangle in a Pull Request. However, Hound sees the comma dangle as a violation because the root .eslintrc.json file does not require the comma dangle and sees it as a violation but we would like Hound to lint against the .eslintrc.json file in the subdirectory so that the file in our Pull Request would not have a violation.

@TomasBarry
Copy link
Contributor

Any ideas on this @buschtoens?

@gylaz
Copy link
Member

gylaz commented Jul 16, 2019

Assuming, foo/bar/.eslintrc.json and foo/baz/.eslintrc.json do specify root: true, would Hound be smart enough to understand that foo/.eslintrc.json should not lint the foo/bar and foo/baz directories?

Yes, because in the end Hound shells out to ESLint and let's it do its thing. The only difference is we selectively fetch only the necessary files for the lint to happen.

But Hound is only running the code against the root set of rules.

That's because currently Hound only knows about a single configuration file.

@TomasBarry
Copy link
Contributor

@gylaz, so is it be possible to inform Hound of the extra eslintrc.json files?

@hlascelles
Copy link

This is still an issue for us, is there any progress on resolving it?

boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
- PR #2
- add travis / houndci
- add mocha test
- front-end (wip draft)
- eslint
- multiple eslint issue: houndci/hound#1706 - keep one global file
boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
- PR #2
- add travis / houndci
- add mocha test
- front-end (wip draft)
- eslint
- multiple eslint issue: houndci/hound#1706 - keep one global file
boly38 added a commit to boly38/jardiCal that referenced this issue Oct 13, 2020
- PR #2
- add travis / houndci
- add mocha test
- front-end (wip draft)
- eslint
- multiple eslint issue: houndci/hound#1706 - keep one global file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants