bas950 / eslint-plugin-no-one-time-vars Goto Github PK
View Code? Open in Web Editor NEWDisallows one-time variables
License: Mozilla Public License 2.0
Disallows one-time variables
License: Mozilla Public License 2.0
In specific conditions, no-one-time-vars
does not detect some single-use variables. This affects 2.2.0 and 2.2.1.
There is some interesting behavior when you have a function with the same name:
{
const test = 1;
console.log(test);
}
{
const test = 2;
console.log(test);
}
function test() {}
test();
In this case, the second block with the single-use variable is detected, but the first block is not. Adding more blocks results in all of them being detected, except for the first one. With only 1 block, no errors are found.
Issue
When a one-time-var is set to the result of a method with a side-effect which is accessed in a different function/scope, behavior could be incorrectly modified.
It could potentially affect code with intervals, callbacks, or global variable modification. This may be difficult to detect.
Examples
function example() { clearInterval(interval); } const interval = setInterval(example, 3000);// interval is no longer created function example() { clearInterval(setInterval(example, 3000)); }
Issue:
When using this plugin on code such as:
const [, foo] = "foobar".match(/regex/) || [];
console.log(foo);
and running it using the --fix
option, the code is incorrectly changed.
Expected:
console.log(("foobar".match(/regex/) || [])[1]);
Actual:
console.log("foobar".match(/regex/) || [][1]);
For files that export variables, but only use it once, this rule may remove them, which can break imports in other files.
Example:
// file1.ts
export const test = doSomething(),
test2 = test.doSomething();
// file1.ts
export const test = doSomething();
export const test2 = test.doSomething();
In these cases, the test
variable may be removed, which could break code in another file:
// file2
import { test, test2 } from "./file1"; // Module 'file1' has no exported member 'test'.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.