Giter Club home page Giter Club logo

eslint-plugin-es5's Introduction

eslint-plugin-es5

Build Status Cult Of Martians

ESLint plugin for ES5 users.

Why?

Sometimes someone doesn't want to or can't use Babel. Even if you support modern browsers or node.js, JS engines have bugs like broken block-scoping. Maybe you only want to forbid usage of for-of in your project.

If this concerns you, this plugin should help you.

Installation

npm install --save-dev eslint-plugin-es5

Usage

Add the plugin to your .eslintrc:

{
  "plugins": [
    "es5"
  ]
}

And then any of the rules listed below like this:

{
  "rules": {
    "es5/no-arrow-functions": "error"
  }
}

Also you can extend one of presets:

{
  "extends": [
    "eslint:recommended",
    "plugin:es5/no-es2015"
  ]
}

Available presets:

  • plugin:es5/no-es2015: Forbid ES2015 usage.
  • plugin:es5/no-es2016: Forbid ES2016 usage.

List of supported rules

  • es5/no-es6-methods Forbid ES2015 methods for Array and String
  • es5/no-es6-static-methods Forbid ES2015 static methods for Array, Math, Number, and Object. You can enable specific functions: "es5/no-es6-static-methods": ["error", { exceptMethods: ["Math.imul"] }]
  • es5/no-arrow-functionsπŸ”§: Forbid arrow-functions.
  • es5/no-binary-and-octal-literalsπŸ”§: Forbid binary and octal literals.
  • es5/no-block-scoping: Forbid let and const declarations. You can enable them using options: "es5/no-block-scoping": ["error", { "let": true }]
  • es5/no-classes: Forbid ES2015 classes.
  • es5/no-computed-properties: Forbid computed properties.
  • es5/no-default-parameters: Forbid default parameters.
  • es5/no-destructuringπŸ”§: Forbid destructuring statements.
  • es5/no-exponentiation-operator: Forbid exponentiation operator a ** b usage.
  • es5/no-for-of: Forbid for-of statements.
  • es5/no-generators: Forbid generators usage.
  • es5/no-modules: Forbid ES2015 modules usage.
  • es5/no-object-super: Forbid super/super.foo() calls.
  • es5/no-rest-parameters: Forbid rest parameters.
  • es5/no-shorthand-propertiesπŸ”§: Forbid shorthand properties.
  • es5/no-spreadπŸ”§: Forbid ...spread expressions.
  • es5/no-template-literalsπŸ”§: Forbid template strings usage.
  • es5/no-typeof-symbol: Forbid typeof foo === 'symbol' checks.
  • es5/no-unicode-code-point-escapeπŸ”§: Forbid Unicode support in code point escape.
  • es5/no-unicode-regex: Forbid Unicode support in RegExp.

License

MIT

eslint-plugin-es5's People

Contributors

ahwayakchih avatar ai avatar fanatid avatar joshkel avatar macklinu avatar nkt avatar ota-meshi avatar ryan-gray avatar sapegin avatar trysound avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

eslint-plugin-es5's Issues

1.5 release changes

The project has no ChangeLog.md and Releases miss 1.4 and 1.5. What were features of that 2 releases?

const and let is still allowed

I'm using your es5 plugin which is very nice however eslint still is not complaining about const and let.
Unfortunately our environment does not support const nor let (which come from es6)

no-es6-methods rule should have an "exceptMethods" option

I expected the no-es6-methods rule to accept an exceptMethods option, the same way that no-es6-static-methods does. However, it does not.

So I used patch-package to patch [email protected] to add that rule option:

diff --git a/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js b/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
index b313f28..260cbd1 100644
--- a/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
+++ b/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
@@ -52,9 +52,22 @@ module.exports = {
     docs: {
       description: 'Forbid methods added in ES6'
     },
-    schema: []
+    schema: [{
+      type: 'object',
+      properties: {
+        exceptMethods: {
+          type: 'array',
+          items: {
+            type: 'string'
+          }
+        }
+      }
+    }]
   },
   create(context) {
+    const options = Object.assign({ exceptMethods: [] }, context.options[0]);
+    const exceptMethods = new Set(options.exceptMethods);
+
     return {
       CallExpression(node) {
         if(!node.callee || !node.callee.property) {
@@ -77,7 +90,7 @@ module.exports = {
         const es6Functions = [].concat(
           es6ArrayFunctions,
           es6StringFunctions
-        );
+        ).filter((name) => !exceptMethods.has(name));
         if (es6Functions.indexOf(functionName) > -1 && !isPermitted(node.callee)) {
           context.report({
             node: node.callee.property,

This issue body was partially generated by patch-package.

Target specific presets

plugin:es5/no-es2015 presets are great. But we could go further.

Main problem with ES2015+ features is compatibility problems. So let’s create a preset based on browsers, node version. Like: plugin:es5/ie, plugin:es5/modern-browsers (only Edge), plugin:es5/node4.

Better docs

We could make docs much better (and promote project):

  • Add rules list to README.md.
  • Add examples, why ES6 code could broke your production (like Safari and const problem).

Does not catch Async/Await

It appears that this plugin does not catch instances of async/await in code. My current setup:

I am currently bundling my code with Webpack 4 and using dynamic import() static import from in my otherwise ES5 JS files. When I started using import(), I was getting a parsing error:

error: Parsing error: Unexpected token import at ....

And according to many other threads, they suggest using the "babel-eslint" parser so I added that to my .eslintrc.
(vuejs/eslint-plugin-vue#204)

But now, async/await (and maybe other things?) are successfully being parsed and then not being caught by this plugin.

I would think that this plugin should catch all non-ES5 compliant code which is why I am filing this bug. If you are aware of another way to use dynamic import() with eslint without the "babel-eslint" plugin, I would also be interested in that approach and relying on parsing errors for non ES5 language constructs.

Thanks!

Add rule/option for only allowing `let` declarations in `for ... in` for IE11

First: thank you for this plugin, it's pretty useful. I prefer to use the baseline JavaScript for the legaciest browser I support, i.e. IE11. For keeping my JS fully IE11 compatible I can disable the no-block-scope rule since that is OK most of the time. But it seems that IE11 doesn't like const declarations in for (const item in items) loops. It'd be really cool if this plugin added a rule or expanded the options of the block scoping rule to (dis-)allow this usage of const. Thanks, again, have a nice day!

Send PR to airbnb ES5 config

I think it will be good promotion for project.

Don’t forget to:

  1. Describe why it is important for AirBnB. Like ES6 features could broke JS.
  2. Mention developers who often accept PRs in repo, so they will be noticed about PR by email.

no-es6-methods a bit too strict

an innocent file like this:

var x
x.values()

Will fail eslint with this error:

ES6 methods not allowed: values  es5/no-es6-methods

This is my .eslintrc file:

{
  "extends": [
    "plugin:es5/no-es2015"
  ]
}

In short, I think there's no easy way to tell if x (in the example above) is an array or something that really does have .values() - so I propose that we drop these rules... WDYT?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.