Closed CoryDanielson closed 3 years ago
I still need to test these changes against a repo locally to make sure that the config change is backwards compatible, and that it accepts the config as I expected it to. I copied the config code over from another popular plugin that accepts config
I just confirmed that this works locally, by importing the package from my branch/commit. I was able to update the warning level from error to warning, and the output from eslint was updated appropriately. I also added "validateThis": true
and tested with it set to false
and removed the property entirely and the output matched what was expected based on the unit tests.
// package.json
"eslint-plugin-jquery": "https://github.com/CoryDanielson/eslint-plugin-jquery#e0f74e319786bad8123895c9e2fb23b5d599ed6b",
Why would you limit this to this
? What if I have a closure and need to do var that = this
?
Also why would this be a per-rule setting instead of a global setting?
I agree with both - I've since switched to using eslint-plugin-no-jquery. Updating this PR to use global configuration shouldn't be too much work - but it's supported out of the box in the other lint rule. I was not aware of that rule at the time of writing this.
Addresses #33
Changes
These changes update the plugin to accept a boolean
validateThis
option that determines if rules should validate against potential jQuery usages off ofthis.$<propertyName>
. By default, this option isfalse
, so these changes are backwards compatible. The motivation here is to use this plugin to validate a codebase with Backbone.js, wherethis.$el
is a standardized reference to a jQuery-wrapped element.The only changes are that each rule accepts a config (see question below), that is passed along to
isjQuery
andtraverse
. IfvalidateThis
is enabled,traverse
will return the property node rather than the root node for aMemberExpression
that is a referencesthis.<something>
. This means that it would return the$el
for a line that start withthis.$el
. The same logic is then used on this property withinisjQuery
to determine if it's a jQuery reference (id with$
)Tests
I've added 2 tests to each applicable rule to validate that usages of
this.$foo.<disallowed-jQuery-call>()
are prevented whenvalidateThis
is true, but allowed whenvalidateThis
is false. The same test code was used for the true/false conditions ofvalidateThis
, but with different options.Open Question
This changes updates the plugin to accept the
validateThis
option config. Each rule accepts the option, despite many rules not using it.validateThis
be updated to disallow potential jQuery usage off ofthis
?this.$.when()
despite accepting thevalidateThis
option.config
variables from rules that do not use them?// eslint-disable-next-line no-unused-vars
in my changesUsage