Comments (14)
I'm not sure exactly what you're asking for in this issue. Can you explain
more?
On Sunday, July 14, 2013, Ilya Volodin wrote:
I had exactly the same idea about implementing linter for javascript some
time ago, I even started writing it (using esprima and per node iterators).
But what I wanted to do differently from jshint/jslint is to add an ability
to identify frameworks that are used in the code and run custom rules on
them.For example, identifying that user is using Backbone, and running custom
rules that would require all models to have initialize function. Or
checking for complex selectors if they are using jQuery.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/36
.
Nicholas C. Zakas
@SlickNet
Author, Professional JavaScript for Web Developers
Buy it at Amazon.com:
http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691/ref=sr_1_3
from eslint.
I would like to be able to set up context first, something that would look like this:
module.exports = function(context) {
return {
"MemberExpression": function(node) {
if (node.object.name === "Backbone" && node.property.name === "Model") {
context.setContext("Backbone");
}
}
}
}
And then create rules that would apply only to the context "Backbone", for example.
from eslint.
Ah, I see what you mean. I'll rephrase: you want to be able to set some shared information such that multiple rules can use it to do the right thing. Let me know think about how I would do this. I don't think setContext()
is quite right, because you could be using Backbone, jQuery, Underscore, etc. all in one.
from eslint.
Right, that's better way of phrasing it. However, just to add on top of it a bit, I would not only like to share some information, I would also like to limit some of the rules to only be called when you are within the AST branch that is marked with certain information. Like if you are within the branch of code that starts with $, it would get marked with jQuery, and jQuery rules should be only executed within that branch. Once you are out that branch, no jQuery rules should apply anymore.
from eslint.
Hmmm...okay, that complicates things a bit. I think what you're asking for
are context-aware rules, which is a bit out of scope for what I'm thinking
for version 1.0. That's not to say it can't be done, but there are a lot of
foundation pieces that have to be put in place first before I'd want to
tackle context-aware rules.
On Mon, Jul 15, 2013 at 1:17 PM, Ilya Volodin [email protected]:
Right, that's better way of phrasing it. However, just to add on top of it
a bit, I would not only like to share some information, I would also like
to limit some of the rules to only be called when you are within the AST
branch that is marked with certain information. Like if you are within the
branch of code that starts with $, it would get marked with jQuery, and
jQuery rules should be only executed within that branch. Once you are out
that branch, no jQuery rules should apply anymore.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/36#issuecomment-21000469
.
Nicholas C. Zakas
@SlickNet
Author, Professional JavaScript for Web Developers
Buy it at Amazon.com:
http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691/ref=sr_1_3
from eslint.
I think you will have to implement something like that even for the basic rules. It might not be context aware rules, but you will at least have to implement scope aware rules. Otherwise it will be very tough to create rules for something like that: http://jslinterrors.com/a-is-a-statement-label/ or http://jslinterrors.com/const-a-has-already-been-declared/ You can run your rule on the whole tree and search for all const declarations, but that means that in order to match even all the rules of the jshint/jslint, you will probably need to iterate over the AST 30-40 times, which isn't a scalable solution.
from eslint.
Yes, scope awareness is something that will need to be built in (I'm
investigating escope), however, these rules will not be turned on or off
based on the scope.
On Mon, Jul 15, 2013 at 4:13 PM, Ilya Volodin [email protected]:
I think you will have to implement something like that even for the basic
rules. It might not be context aware rules, but you will at least have to
implement scope aware rules. Otherwise it will be very tough to create
rules for something like that:
http://jslinterrors.com/a-is-a-statement-label/ or
http://jslinterrors.com/const-a-has-already-been-declared/ You can run
your rule on the whole tree and search for all const declarations, but that
means that in order to match even all the rules of the jshint/jslint, you
will probably need to iterate over the AST 30-40 times, which isn't a
scalable solution.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/36#issuecomment-21010712
.
Nicholas C. Zakas
@SlickNet
Author, Professional JavaScript for Web Developers
Buy it at Amazon.com:
http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691/ref=sr_1_3
from eslint.
I think for the initial version, it would be fine to not turn off the context aware rules out of context, just give them awareness, just like you described and then short circuit them in the rule implementation. In the future version, it would be nice to only execute those rules when the context is set, to improve performance.
from eslint.
Agree.
On Mon, Jul 15, 2013 at 4:36 PM, Ilya Volodin [email protected]:
I think for the initial version, it would be fine to not turn off the
context aware rules out of context, just give them awareness, just like you
described and then short circuit them in the rule implementation. In the
future version, it would be nice to only execute those rules when the
context is set, to improve performance.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/36#issuecomment-21011701
.
Nicholas C. Zakas
@SlickNet
Author, Professional JavaScript for Web Developers
Buy it at Amazon.com:
http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691/ref=sr_1_3
from eslint.
Something like this could be done with an esquery based rules engine. I'd be interested in some other peoples thoughts on using it for rule definitions. With a selector based rules engine I can imagine rule sets only applying if a node matches a given selector (equivalent to a context).
from eslint.
I didn't know about esquery. @nzakas could we add this in? This would make it much easier to create complex rules. For example, there's a rule in jshint that prevents you from creating functions inside for loop.. Since it supports parent>child and descendant, events can be done in a much nicer way. I was actually planning on adding something like that to the events.
from eslint.
I've chatted with @jrfeenst and we can definitely look at it down the road. I don't think either project is mature enough to really put a lot of work in integration at this point. I'd rather focus on getting to feature parity with JSHint/JSLint, do some stabilization, and then we can explore what the gaps and pain points are for people. That would be the time to start evaluating esquery seriously.
from eslint.
@jrfeenst: @nzakas: @ilyavolodin: I created esdispatch for this. It will allow eslint rules to operate on esquery selectors rather than just node types. It still uses a single traversal, so should be no less efficient, will be backwards compatible with current rules (because node types are also valid queries), and will allow us to greatly simplify many of the eslint rules. Pull request coming soon.
(P.S. sorry for the double post, I accidentally posted this in the wrong issue the first time)
from eslint.
@michaelficarra Very nice! This would allow for much simpler rules. It will prevent us from doing things like inline comment parsing easily (like turning rules off/on based on the comments per line), but we can find some other way of doing that.
from eslint.
Related Issues (20)
- Rule Change: Add suggestion fixer to no-case-declarations HOT 4
- The Eslint command is failing with error "Oops! Something went wrong! :( ESLint: 9.0.0 Error: Could not find config file." This is referring from file https://github.com/eslint/eslint/blob/main/lib/eslint/eslint.js HOT 4
- New Rule: prefer-structured-clone HOT 1
- Bug: npm init @eslint/config generates broken-by-default config file HOT 2
- Rule Change: `no-restricted-exports` to accept Regex patterns HOT 7
- Bug: defining a global named `__defineSetter__` doesn't work HOT 1
- Init wizard not generating flat config HOT 8
- Bug: v9.0.0 has prevented ancestor glob patterns HOT 4
- Change Request: Some tweaks to getFunctionHeadLoc HOT 3
- Bug: flat configs are processing ignored directories and applying rules that were scoped to other directories HOT 1
- Bug: ESLint never stops when analyzing linter issues in the project HOT 17
- Docs: `no-unreachable` is not necessarily handled by TypeScript HOT 1
- Bug: eslint v8 with flat config and airbnb-base throws cryptic error
- Docs: custom rule tutorial doesn't work with v9 HOT 1
- Scheduled release for May 3rd, 2024 HOT 2
- Change Request: Make it easier to inherit flat configs from the repo root HOT 12
- This method cannot be used with flat config. Add your entries directly into the config array. HOT 1
- Docs: context migration suggestions fail on earlier v8 versions
- Bug: (Config (unnamed): Unexpected key "baseDirectory" found.) HOT 1
- 📈 Tracking: ESLint v9 support HOT 5
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.