Support separate requires in one-var
See original GitHub issueESLint Version: 2.10.1
Problem:
A common request (e.g, #3091, #1232) is for the one-var
rule to properly function in tandem with no-mixed-requires
. I agree with this opinion, as the two methods are part of the core set of rules provided with ESLint and should properly support each other. I also believe there is a way to support this without introducing a dependency between the two rules.
Recommended Solution:
I believe this should not be a plugin, as both commands are part of the core library and cause conflict with each other. A better solution would be to add an optional parameter separate-requires
to one-var
that allows for require
keywords to be separated into a single block, while assignments are in another block (similar to the intent of the two-var plugin).
For example:
"one-var": ["error", {
"separate-requires": true, // (New) Enforces requires to be separate from declarations
"var": "never",
"let": "never",
"const": "never"
}]
This will allow ESLint to properly support it’s built-in plugins without changing the default functionality of the one-var
rule. With the above configuration:
This code would result in an error:
const gulp = require('gulp'),
myModule = require('./some/module'),
myVar1 = 1,
myVar2 = 2;
This code would be valid:
const gulp = require('gulp'),
myModule = require('./some/module');
const myVar = 1,
myVar = 2;
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:22 (19 by maintainers)
Top GitHub Comments
@onurtemizkan Was like 2/3 of the way done, but don’t let me stop you!
I will take a look into getting a PR up for this sometime this week/weekend.