eslint-plugin-compat icon indicating copy to clipboard operation
eslint-plugin-compat copied to clipboard

Array methods not reporting errors

Open davidbarredo opened this issue 6 years ago • 4 comments

The plugin is no reporting errors for array methods such as:

arr1 = [1, 2, [3, 4]];
arr1.flat();

The flat method is not supported in IE (https://caniuse.com/#feat=array-flat), but the plugin is not reporting it as an error.

To test it, just add these lines into index.js file inside the demo: https://github.com/amilajack/eslint-plugin-compat-demo

I've just saw https://github.com/amilajack/eslint-plugin-compat/issues/168#issuecomment-462009281 and tested Array.flat();. Is showing the error.

Maybe adding these methods as a warning when not able to check te type is a good enough solution.

davidbarredo avatar Aug 27 '19 07:08 davidbarredo

I ran into the same issue today. Any update on this?

ReneF1 avatar Feb 04 '20 13:02 ReneF1

@davidbarredo After thinking about this for some time I think that this is finally a good solution for now. Would love if anyone could work on this

amilajack avatar Feb 06 '20 20:02 amilajack

I think this should be closed in favor of the more generic #206 (letting that apply to all ES features).

brettz9 avatar Apr 01 '20 01:04 brettz9

As proof of concept(PoC), I've created eslint-plugin-typescript-compat to resolve this issue. This rule use TypeScript compiler and lint TypeScript codebase.

For example, TypeScript Compiler know arr1 is Array instance type. So, eslint-plugin-typescript-compat can lint the usage of Array.prototype.flat method.

const arr1 = [1, 2, [3, 4]];
arr1.flat();
^^^^
TypeScript compiler know `arr1` is `Array` instance

This plugin get type information from TypeScript and lint it.

  • Test case: https://github.com/azu/eslint-plugin-typescript-compat/blob/2fc9107e87da431ec269f06495b7f9591d43d097/tests/lib/rules/compat.ts#L68-L80

📝 This plugin only works on TypeScript. It requires TypeScript compiler and TypeScript codebase. Currently, this plugin only supports ECMAScript methods like Array.prototype.flat or Array.from. In other words, this plugin does not support detection for Build-in Object or DOM API yet. These features are duplicate works to eslint-plugin-compat. So I re-think about the area of ​​responsibility of eslint-plugin-typescript-compat

  • https://github.com/azu/eslint-plugin-typescript-compat/issues/1

azu avatar Aug 19 '20 08:08 azu