Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

ESLint to source code only. #189

Closed
constgen opened this issue Apr 23, 2017 · 5 comments
Closed

ESLint to source code only. #189

constgen opened this issue Apr 23, 2017 · 5 comments
Assignees
Labels

Comments

@constgen
Copy link
Contributor

Currently if ESlint presets are installed in the project the rules are applied to all files starting from the root. Exceptions are node_modules and bower_components that are excluded by default in the ESLint. We need to apply ESLint rules only to source files (./src by default).

What the problem is:

Lets say you use VSCode and configure everything to integrate project ESLint rules to the editor and to autoformat files on save. In this setup there is no chance to save files that are not ESLint valid. This breaks local custom middlware for the advanced Neutrino configuration. For example ESLint may add trailing commas which will break NodeJS interpretator when neutrino start.

@eliperelman
Copy link
Member

Yeah, I think something might have been changed, because I'm pretty sure we had it set at one point that ESLint operates against only the source directory. Looking at the lint middleware:

https://github.com/mozilla-neutrino/neutrino-dev/blob/master/packages/neutrino-middleware-eslint/index.js#L38-L39

My guess is we would want to set this to neutrino.options.source when neither include nor exclude have been specified.

@constgen
Copy link
Contributor Author

What you mentioned is a different thing. This checks files when they are resolved through the dependency tree. What I am talking about is the editor validation errors. The editor just grubs the ESLint rules generated from the Neutrino and applies them to any files it wants without considering Webpack include and exclude. Tell me if I am wrong.
As far as I know ESLint itself doesn't have include but it has kind of exclude that is described in a glob format. So we can use it to exclude everything besides src. Need only to think how to preserve the neutrino.options

@eliperelman
Copy link
Member

Ah I see now. You are correct; there is no way to specify this information in the configuration. I remember seeing an issue to change this in the eslint repo somewhere, but I don't have it off hand. Instead, you should probably whitelist the files you want linted, like we do in neutrino-dev:

eslint packages/*/*.js packages/*/src/**/*.js packages/neutrino/bin/*

Essentially you would want to lint your source:

eslint src/**/*.js --ext .js,.jsx

Something like that.

Since ESLint doesn't accept file parameters from configuration, there is no simple way to have their CLI respect neutrino.options.source. This would probably mean running some other script to generate a glob, and outputting this to the ESLint CLI:

eslint $(get_source_glob)

@constgen
Copy link
Contributor Author

I have investigated this problem deeper. You seem to be right that we can't configure it by ourselves. And I think I even found the issue you mentioned in their repository eslint/eslint#3529.

So what solution I found. Manually configure it using .eslintignore in your project. I am going to update the documentation of ESlint middleware to explain to everybody how to make it work in editors.

@constgen
Copy link
Contributor Author

Done in #205

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants