question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support separate requires in one-var

See original GitHub issue

ESLint 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:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:22 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeletschercommented, Jul 8, 2017

@onurtemizkan Was like 2/3 of the way done, but don’t let me stop you!

1reaction
mikeletschercommented, Jun 12, 2017

I will take a look into getting a PR up for this sometime this week/weekend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

one-var-declaration-per-line - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Secondary Expansion (GNU make)
Previously we learned that GNU make works in two distinct phases: a read-in phase and a ... the first (unescaped) variable reference to...
Read more >
Declaring multiple variables in JavaScript - Stack Overflow
It's common to use one var statement per scope for organization. ... It will unpack values from arrays, or properties from objects, into...
Read more >
240-29: Steps to Success with PROC MEANS - SAS Support
You can put as many. (numeric) variables as you need/want in to one VAR Statement in your PROC MEANS task. The Output Window...
Read more >
A tour of the Dart language
Dart also supports multi-line and document comments. For details, see Comments. ... Using null safety requires a language version of at least 2.12....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found