wikimedia / eslint-plugin-no-jquery

Control allowance of certain jQuery functions, and suggest or autofix alternatives.
MIT License
32 stars 8 forks source link

Implement fixable rules when possible #115

Open stof opened 5 years ago

stof commented 5 years ago

Some of the rules could be fixed quite easily. For instance, migrating from $.isArray() to Array.isArray is straightforward. It would be great if such rules could be implemented as fixable, so that ESLint can fix them automatically.

Ed: Adding checklist here so it comes up in the task list:

stof commented 5 years ago

Most rules won't be fixable, but that will still be nice for the few ones benefiting from this.

edg2s commented 5 years ago

Note that some rules will have subtle changes that mean we can't autofix, for example handling undefined arguments: $.inArray( myUndefinedVar, 'foo' ) will not throw, whereas myUndefinedVar.indexOf will

edg2s commented 5 years ago

Here's a first pass of rules we could probably write fixers for:

(moved to first comment)

stof commented 5 years ago

$.now() can be migrated to Date.now() easily too

edg2s commented 5 years ago

Date.now() is es6 and we'd like to maintain compatibility with es5 for now.

stof commented 5 years ago

Date.now is supported in IE9+: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Browser_compatibility

Btw, $.now() is implemented using Date.now() already: https://github.com/jquery/jquery/blob/3.4.1/src/deprecated.js#L82 So using it will not regress browser support.

Btw, it is part of ES 5.1, not of ES 6.

edg2s commented 3 years ago

Note that some rules will have subtle changes that mean we can't autofix, for example handling undefined arguments: $.inArray( myUndefinedVar, 'foo' ) will not throw, whereas myUndefinedVar.indexOf will

Rules that can't be auto-fixed can be implemented as suggestions. The message can be used to explain the limitations of the fix.