Comments (4)
Thanks for opening this issue!
not sure if you intend for "global" to also mean top-level in a module
Good question. To be honest I hadn't considered it either way. But now that you bring it up, yes I think having an arrow function in the outermost scope (whether that's the real global or whether it's the top-most scope of a module) should have been covered by the "global"
setting.
So, yes, it seems like it is a bug (in the sense of unintentional shortcoming).
To fix, yes, I think these lines need to be updated:
https://github.com/getify/eslint-plugin-proper-arrows/blob/master/lib/index.js#L730-L735
We'd probably best change them to:
["global","module",].includes(scope.upper.upper.type)
// ..
["global","module",].includes(scope.upper.type)
And for tests, we'd need to add these config presets at the top:
whereModuleGlobalDefault: {
parserOptions: { ecmaVersion: 2015, sourceType: "module", },
rules: { "@getify/proper-arrows/where": ["error",{property:false,export:false,trivial:true,},], },
},
whereModuleGlobal: {
parserOptions: { ecmaVersion: 2015, sourceType: "module", },
rules: { "@getify/proper-arrows/where": ["error",{global:true,property:false,export:false,trivial:true,},], },
},
Then we'd need these four tests at the end:
QUnit.test( "WHERE (module-global, default): conforming", function test(assert){
var code = `
function foo() {
var f = x => y;
}
`;
var results = eslinter.verify( code, linterOptions.whereModuleGlobalDefault );
assert.expect( 1 );
assert.strictEqual( results.length, 0, "no errors" );
} );
QUnit.test( "WHERE (module-global, default): violating", function test(assert){
var code = `
var f = x => y;
`;
var results = eslinter.verify( code, linterOptions.whereModuleGlobalDefault );
var [{ ruleId, messageId, } = {},] = results || [];
assert.expect( 3 );
assert.strictEqual( results.length, 1, "only 1 error" );
assert.strictEqual( ruleId, "@getify/proper-arrows/where", "ruleId" );
assert.strictEqual( messageId, "noGlobal", "messageId" );
} );
QUnit.test( "WHERE (module-global): conforming", function test(assert){
var code = `
function foo() {
var f = x => y;
}
`;
var results = eslinter.verify( code, linterOptions.whereModuleGlobal );
assert.expect( 1 );
assert.strictEqual( results.length, 0, "no errors" );
} );
QUnit.test( "WHERE (module-global): violating", function test(assert){
var code = `
var f = x => y;
`;
var results = eslinter.verify( code, linterOptions.whereModuleGlobal );
var [{ ruleId, messageId, } = {},] = results || [];
assert.expect( 3 );
assert.strictEqual( results.length, 1, "only 1 error" );
assert.strictEqual( ruleId, "@getify/proper-arrows/where", "ruleId" );
assert.strictEqual( messageId, "noGlobal", "messageId" );
} );
Also, of course, the docs need to be updated in several places of these sections:
https://github.com/getify/eslint-plugin-proper-arrows/blob/master/README.md#rule-configuration-1
Probably change all references from "top-level/global" to "module-top-level/global" or something like that.
As a side question, now maybe that "global"
name is confusing and should be changed to "outermost"
or "top"
? Not sure if it warrants changing, though. I guess most people will call a top-level module's scope "global" (or "module-global"). So probably don't need to change... but just something to ponder.
from eslint-plugin-proper-arrows.
Thanks!, that was above and beyond clear :D Seems like a nice and easy repo to work with, well done.
A choice had to be made: An export violation is also a module-top-level violation, as I can see it that must be true by definition. To alter the public interface as little as possible I opted for a change such that export violation is tested first, and if one is found then it is not also reported as a global violation. Happy to change it to any direction you prefer, this just seemed to me to be the most intuitive.
from eslint-plugin-proper-arrows.
An export violation is also a module-top-level violation, as I can see it that must be true by definition.
Good point, glad you brought it up.
I think the typical pattern I've used is that any overlapping rule is reported multiple times. In other words, a single line can have any number of rule violations applied to it. That's especially true since different rules might apply to different parts of the same line.
My reasoning was: it would be quite annoying to me if I found a line violating a linting rule, and then fixed that violation, only to have that same line now reported again for a different violation. Of course, this happens if my fix itself introduces the violation. But if the violation was hidden, I find that frustrating.
from eslint-plugin-proper-arrows.
An export violation is also a module-top-level violation, as I can see it that must be true by definition.
Good point, glad you brought it up.
I think the typical pattern I've used is that any overlapping rule is reported multiple times. In other words, a single line can have any number of rule violations applied to it. That's especially true since different rules might apply to different parts of the same line.
My reasoning was: it would be quite annoying to me if I found a line violating a linting rule, and then fixed that violation, only to have that same line now reported again for a different violation. Of course, this happens if my fix itself introduces the violation. But if the violation was hidden, I find that frustrating.
Yeah that makes sense. I'll update the PR.
EDIT: Done, great precise feedback thanks
from eslint-plugin-proper-arrows.
Related Issues (20)
- Create a wizard for picking rules config
- Add "location" rule to forbid use of arrow functions in certain places HOT 1
- Add ternary `? :` to the list forbidden of concise return expressions
- Prevent arrow functions that implicitly return arrow functions HOT 1
- Allowing no name for class property functions? HOT 10
- Elision of destructured function parameters causes crash HOT 1
- add config preset(s) HOT 5
- treat `void ..` expression as "trivial" arrow body
- is @getify/proper-arrows/params needed? HOT 2
- @getify/proper-arrows/names should follow func-names schema HOT 2
- Add `id` to the default allowed list of short params HOT 5
- False positive on object destructuring in arrow function parameters HOT 4
- Errors when disabling the rules in Create React App HOT 4
- some "where" rules do not notify warning/error on text editors HOT 8
- Extend definition of trivial to include comparisons HOT 3
- Include delegations under trivial functions HOT 5
- `where` rule global option detects passing arrow as callback on module level as violation HOT 3
- Add setting to disallow "arrow function declarations" at the global/top level HOT 18
- Ignoring React components defined as an arrow function HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-proper-arrows.