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

Only lint node .js files? (and not browser .js files) #88

Closed
foxtree opened this issue Jul 28, 2017 · 3 comments
Closed

Only lint node .js files? (and not browser .js files) #88

foxtree opened this issue Jul 28, 2017 · 3 comments
Labels

Comments

@foxtree
Copy link

foxtree commented Jul 28, 2017

Is it possible to configure ESLint, such that it will only check eslint-plugin-node rules when the node environment is enabled?

For example, eslint-plugin-node rules would be applied if the following directive existed:
(for files that execute in a Node.js context)

/* eslint-env node */
@jordanbtucker
Copy link

jordanbtucker commented Aug 9, 2017

I would like to add that the rules should only apply when {env: {node: true}}.

Use case:

I have a project with backend and frontend code with this folder structure:

app
|- .eslintrc.json
|- server.js
|- /public
  |- .eslintrc.json
  |- client.js
  |- index.html

/.eslintrc.json:

{
  "env": {
    "node": true
  },
  "plugins": {
    "node"
  },
  "extends": [
    "plugin:node/recommended"
  ]
}

/frontend/.eslintrc.json:

{
  "env": {
    "browser": true,
    "node": false
  }
}

/frontend/client.js:

import _ from 'lodash' // <- node/no-unsupported-features complains here

eslint-plugin-node shouldn't care about unsupported features (or any other rules) when node: false. This is especially troublesome since ESLint doesn't provide a way to disable an entire plugin on a per-folder basis.

@mysticatea
Copy link
Owner

Thank you for this proposal.

However, I don't think it's feasible.
Plugin rules cannot get the value of env which is defined by config files.
Also, there are people which don't use env to avoid defining unnecessary globals.

I'm closing as won't fix.

@nfriedly
Copy link

Hey, I know this is a really old issue, but I ran into the same problem today and I was wondering if anything has changed in the last few years?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants