Giter Site home page Giter Site logo

mysticatea / eslint-plugin-es Goto Github PK

View Code? Open in Web Editor NEW
104.0 5.0 24.0 13.02 MB

ESLint plugin about ECMAScript syntactic features.

Home Page: https://eslint-plugin-es.mysticatea.dev/

License: MIT License

JavaScript 100.00%
eslint eslint-plugin javascript npm-package ecmascript

eslint-plugin-es's Introduction

eslint-plugin-es

npm version Downloads/month Build Status Coverage Status Dependency Status

ESLint plugin which disallows each ECMAScript syntax.

🏁 Goal

Espree, the default parser of ESLint, has supported ecmaVersion option. However, the error messages of new syntax are not readable (e.g., "unexpected token" or something like).

When we use this plugin along with the latest ecmaVersion option value, it tells us the readable error message for the new syntax, such as "ES2020 BigInt is forbidden." Plus, this plugin lets us disable each syntactic feature individually.

πŸ“– Usage

See documentation

πŸš₯ Semantic Versioning Policy

This plugin follows semantic versioning and ESLint's semantic versioning policy.

  • We will release a new minor version to add new rules when TC39 decided to advance proposals to Stage 4. In the minor releases, we don't update configs.
  • We will release a new major version to update configs when new ECMAScript snapshots are available.

πŸ“° Changelog

See releases.

❀️ Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run clean removes the coverage result of npm test command.
  • npm run coverage shows the coverage result of the last npm test command.
  • npm run docs:build builds documentation.
  • npm run docs:watch builds documentation on each file change.
  • npm run watch runs tests on each file change.

eslint-plugin-es's People

Contributors

edg2s avatar lucascabello avatar michaeldeboey avatar mysticatea avatar ota-meshi avatar toptalo avatar yaroslavnikiforov 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  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  avatar

eslint-plugin-es's Issues

New Rule Proposal: `no-top-level-await`

Please describe what the rule should do:

Disallows Top-level await added in ES2022.

https://github.com/tc39/proposal-top-level-await

Provide 2-3 code examples that this rule will warn about:

const strings = await import(`/i18n/${navigator.language}`);

const connection = await dbConnector();

let jQuery;
try {
  jQuery = await import('https://cdn-a.com/jQuery');
} catch {
  jQuery = await import('https://cdn-b.com/jQuery');
}

New version

Hi, @mysticatea. The rules for prototype methods were added 7 months ago, but the new version was not published forcing us to use this plugin from GitHub. Maby already makes sense to publish it on NPM? -)

Published package appears to be broken

Hi, I just installed [email protected] which is the latest according to npm.

simple .eslintrc.js config

...
plugins: [
    'es',
  ],
rules: {
  'es/no-bigint': 'error',
  'es/no-dynamic-import': 'error',
},
...

Running npx eslint . , I got random loads of errors, eg.

  1:1  error  Definition for rule 'es/no-export-ns-from' was not found                es/no-export-ns-from
  1:1  error  Definition for rule 'es/no-import-meta' was not found                   es/no-import-meta
  1:1  error  Definition for rule 'es/no-nullish-coalescing-operators' was not found  es/no-nullish-coalescing-operators

Examining ./node_modules/eslint-plugin-es/lib/index.js it doesn't appear any of these rules exist, they don't appear to be in /lib/rules either ?

Support ESLint 8.x

ESLint v8.0.0 is released πŸŽ‰

It would be awesome to have official ESLint 8 support. πŸ‘Š
I'm happy to help where I can of course πŸ™‚

Type Error: cannot read 'length' of undefined.

Tell us about your environment

  • ESLint Version: 5.1.0
  • Node Version: 8.11.3
  • npm Version: 6.1.0
  • yarn Version: 1.7.0

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

Configuration
module.exports = {
	"parser": "babel-eslint",
	"root": true,
	"plugins": [
		"node",
		"flowtype"
	],
	"extends": ["eslint:recommended", "plugin:node/recommended"],
	"env": {
		"node": true,
		"es6": true,
		"jest": true
	},
	"parserOptions": { "ecmaVersion": 2017, "sourceType": "module"},
	"rules": {
		"no-useless-escape": "off",
		"quote-props": ["error", "as-needed"],
		"no-dupe-keys": "error",
		"quotes": ["error", "double"],
		"no-undef": "error",
		"no-extra-semi": "error",
		"semi": "error",
		"no-template-curly-in-string": "error",
		"no-caller": "error",
		"yoda": "error",
		"eqeqeq": "error",
		"global-require": "off",
		"brace-style": "error",
		"key-spacing": "error",
		"space-in-parens": ["error", "never"],
		"space-infix-ops": "error",
		"indent": ["error", "tab", { "SwitchCase": 1 }],
		"no-extra-bind": "warn",
		"no-empty": "off",
		"no-multiple-empty-lines": "error",
		"no-multi-spaces": "error",
		"no-process-exit": "off",
		"no-trailing-spaces": "error",
		"no-use-before-define": "off",
		"no-unused-vars": ["error", { "args": "none" }],
		"no-unsafe-negation": "error",
		"no-loop-func": "warn",
		"space-before-function-paren": ["error", "never"],
		"space-before-blocks": "error",
		"object-curly-spacing": ["error", "always"],
		"object-curly-newline": ["error", { "consistent": true }],
		"keyword-spacing": ["error", {
			"after": true,
			"overrides": {
				"const": { "after": true },
				"try": { "after": true },
				"throw": { "after": true },
				"case": { "after": true },
				"return": { "after": true },
				"finally": { "after": true },
				"do": { "after": true }
			}
		}],
		"no-console": "off",
		"valid-jsdoc": "error",
		"node/no-unsupported-features": 'off',
		"node/no-deprecated-api": "error",
		"node/no-missing-import": "error",
		"node/no-extraneous-require": ["error"],
		"eol-last": ["error", "always"],
		"newline-per-chained-call": "off",
		"node/process-exit-as-throw": "error"
	},
	"settings": {
    "flowtype": {
      "onlyFilesWithFlowAnnotation": true
    }
  }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

eslint src/

What did you expect to happen?
Throw eslint errors or succeed.

What actually happened? Please include the actual, raw output from ESLint.

I see this error:

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at :function (project/node_modules/eslint-plugin-es/lib/rules/no-trailing-function-commas.js:30:44)
    at listeners.(anonymous function).forEach.listener (project/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (project/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (project/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (project/node_modules/eslint/lib/util/node-event-generator.js:278:22)
    at NodeEventGenerator.enterNode (project/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (project/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    at nodeQueue.forEach.traversalInfo (project/node_modules/eslint/lib/linter.js:861:28)
    at Array.forEach (<anonymous>)
error Command failed with exit code 2.

Since the error was thrown by this package, i thought it would be better to post it here other than on eslint, if it is better to be there, just let me know than i will move it.

Thanks.

Incorporate browser compatibility data

Rather than banning particular ES versions or individual features, I'd like to be able to declare the browser features that are to be supported. This might be for this plugin, or some companion plugin/config that works with it.

As a starting idea...

// .eslinrc.json
{
  "plugins": ["es"],
  "extends": "plugin:es/browserslist"
}
// .browserslistrc
last 3 versions

The es/no-foo rules included in the output config would be dynamic, based on the browsers matching the browserslist spec, looked up against a compatibility database.

Leading on from:

doco has typos

https://mysticatea.github.io/eslint-plugin-es/rules/

The extends: "plugin:es/no-es2018" config enables the following rules.
should read
The extends: "plugin:es/no-2018" config enables the following rules.

The extends: "plugin:es/no-es2017" config enables the following rules.
should read
The extends: "plugin:es/no-2017" config enables the following rules.

etc.
they all give name no-es where the name should be no-

Add higher es version presets to lower one

Lower version preset like no-es5 should include all higher version presets, for easier use.

Currently, if I want disable es5 syntax, I have to do

{
      extends: [
        'plugin:es/no-2020',
        'plugin:es/no-2019',
        'plugin:es/no-2018',
        'plugin:es/no-2017',
        'plugin:es/no-2016',
        'plugin:es/no-2015',
        'plugin:es/no-5',
      ],
}

seems silly, and if someday this plugin add no-2020(Update: we already has no-2020, but missing on website https://eslint-plugin-es.mysticatea.dev/#presets) no-2021, and I didn't update my config, 20202021 syntax will sneak in.

I suggest we include no-2015 in no-5, include no-2016 in no-2015, ..., so to disable es5, I can simply just extends: ['no-5'], for someone only want disable 2018, I suggest new preset no-{version}-only, like no-2018-only.

This will be a breaking change, if you don't want that, we can support this by adding some presets like no-5-above, no-2015-above.

FYI: typescript-eslint@v6 will remove parserServices.hasFullTypeInformation

πŸ‘‹ Hi! I'm one of the maintainers of typescript-eslint. We're getting ready to release a new v6 major version of the tooling, which includes some small breaking changes.

Coming over from typescript-eslint/typescript-eslint#7124: I see this repo contains references to hasFullTypeInformation. That property is something we've never recommended using (see that issue & typescript-eslint/typescript-eslint#7158). We recommend instead using ESLintUtils.getParserServices per https://typescript-eslint.io/developers/custom-rules#typed-rules.

If you really want to "progressively enhance" lint rules, parserServices.program will be null if type information isn't available. But we definitely recommend against that kind of rule behavior changing.

Overall, I'd suggest trying out typescript-eslint@v6 and making sure internal builds & downstream repos still compile & lint nicely with all the changes. Let me know if there's anything we can do to help with the v6 upgrade! πŸ’–

New Rule Proposal: `no-class-fields`

Please describe what the rule should do:

Disallows Class Fields added in ES2022.

https://github.com/estree/estree/blob/master/es2022.md

Provide 2-3 code examples that this rule will warn about:

https://github.com/tc39/proposal-class-fields

class Counter  {
  x = 0;
}

https://github.com/tc39/proposal-private-methods

class Counter  {
  #xValue = 0;

  get #x() { return #xValue; }
  set #x(value) {
    this.#xValue = value;
    window.requestAnimationFrame(this.#render.bind(this));
  }

  #clicked() {
    this.#x++;
  }

  constructor() {
    super();
    this.onclick = this.#clicked.bind(this);
  }

  connectedCallback() { this.#render(); }

  #render() {
    this.textContent = this.#x.toString();
  }
}

https://github.com/tc39/proposal-static-class-features

class CustomDate {
  // ...
  static epoch = new CustomDate(0);
}
export class JSDOM {

  static async fromURL(url, options = {}) {
    return JSDOM.#finalizeFactoryCreated(new JSDOM(body, options), "fromURL");
  }

  static #finalizeFactoryCreated(jsdom, factoryName) {
    // ...
  }
}

Create optional rules for prototype methods

I found your comment at explaining why these aren't available at the moment: #2 (comment). While it is true that you will get some false positives, many of the methods have unique enough names that most of the time you won't, and the rare cases that do can be fixed with an inline exception.

I suggest creating these rules and put them in separate rule groups so they are not enabled by default, but can be used when users are happy to deal with the small number of false positives.

We have a similar set of rules for Wikipedia at https://github.com/wikimedia/eslint-config-wikimedia/tree/master/language and would like to be able to use this library instead, but the prototype method rules are important to us and catch lots of issues.

Definition for rule 'es/no-string-prototype-replaceall' was not found

When trying to use only the "es/no-string-prototype-replaceall": "error" rule, eslint reports that this rule is not available:
Definition for rule 'es/no-string-prototype-replaceall' was not found

.eslintrc.json:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2021,
    "sourceType": "module",
    "project": "./tsconfig.json"
  },
  "plugins": ["@typescript-eslint", "es",
  "rules": {
    "es/no-string-prototype-replaceall": "error"
  }
}

I'm using "eslint-plugin-es": "^4.1.0",

When, as a test, using es/no-async-iteration instead of the replaceall rule, it works.

Is there anything else I need to configure to make checks only for this rule work?

Add ES3 rules

Why? For some specific use cases, it could be useful to disable ALL ES built-ins. In my case, it's writing safe polyfills which don't use methods directly for preventing monkey-patching by something with observable effects.

New Rule Proposal: `no-array-prototype-at` and `no-string-prototype-at`

Please describe what the rule should do:

  • no-array-prototype-at ... Disallow Array.prototype.at and TypedArray .prototype.at method.
  • no-string-prototype-at ... Disallow String.prototype.at method.

These methods will be added in ES2022.

https://github.com/tc39/proposal-relative-indexing-method

Provide 2-3 code examples that this rule will warn about:

var e = array.at(-1);
var e = typedArray.at(-1);
var c = string.at(-1);

Do you think we should rename the rule and to check both arrays and strings?

Support ESLint 7.x

ESLint v7.0.0 is released πŸŽ‰

It would be awesome to have official ESLint 7 support. πŸ‘Š
I'm happy to help where I can of course πŸ™‚

Add a TypeScript preset to turn off rules that the tsc compiler correctly transpiles

At the moment, we're using one of the restrict-to-esNNNN presets, which are really great. However, when using TypeScript, there are a lot of things that tsc transpiles correctly regardless of target, so we end up "canceling" a set of rules that are perfectly fine with TypeScript:

## ES2020

# Disallow nullish coalescing operators
# https://eslint-plugin-es.mysticatea.dev/rules/no-nullish-coalescing-operators.html
# This is correctly transpiled by TypeScript
es/no-nullish-coalescing-operators: off

# Disallow optional chaining
# https://eslint-plugin-es.mysticatea.dev/rules/no-optional-chaining.html
# This is correctly transpiled by TypeScript
es/no-optional-chaining: off

## ES2019

# Disallow optional catch binding
#Β https://eslint-plugin-es.mysticatea.dev/rules/no-optional-catch-binding.html
# This is correctly transpiled by TypeScript
es/no-optional-catch-binding: off

## ES2018

# Disallow async iteration
# https://eslint-plugin-es.mysticatea.dev/rules/no-async-iteration.html
# This is correctly transpiled by TypeScript
es/no-async-iteration: off

# Disallow rest/spread properties
# https://eslint-plugin-es.mysticatea.dev/rules/no-rest-spread-properties.html
# This is correctly transpiled by TypeScript
es/no-rest-spread-properties: off

##Β ES2017

# Disallow async function declarations
# https://eslint-plugin-es.mysticatea.dev/rules/no-async-functions.html
# This is correctly transpiled by TypeScript
es/no-async-functions: off

# Disallow trailing commas in parameter/argument lists
# https://eslint-plugin-es.mysticatea.dev/rules/no-trailing-function-commas.html
# This is correctly transpiled by TypeScript
es/no-trailing-function-commas: off

It would be really nice if there was an extra preset to load at the end that cancels those rule correctly, similarly to how eslint-config-prettier turns off all rules that are unnecessary:

extends:
  - plugin:es/restrict-to-es2015
  - plugin:es/typescript

no-atomics and no-shared-array-buffer not working

Hi :)

I've configured these 4 rules:
'es/no-atomics': 'error', 'es/no-shared-array-buffer': 'error', 'es/no-regexp-lookbehind-assertions': 'error', 'es/no-export-ns-from': 'error',

no-atomics and no-shared-array-buffer are not working.

This code snippet:
`const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

	ta[0] = 5; // 5

	Atomics.add(ta, 0, 12); // 5
	// eslint-disable-next-line no-undef
	Atomics.load(ta, 0); // 17`

eslint (v7.32) doesn't prevent it from using. It says 'no-undef', and if adding this exception, everything is ok...

es/no-promise-prototype-finally doesn't work

Hi, I'm using version 4.1.0.
I'm getting the following error when using es/no-promise-prototype-finally
1:1 error Definition for rule 'es/no-promise-prototype-finally' was not found es/no-promise-prototype-finally

This is my eslint config:

module.exports = {
  parserOptions: {
    ecmaVersion: 5
  },
  extends: [
    'eslint:recommended',
    'plugin:jest/recommended',
    'plugin:es/restrict-to-es5'
  ],
  plugins: [
    'jest',
    'es'
  ],
  rules: {
    'es/no-promise-prototype-finally': 2,
    'es/no-promise': 0,
  },
  env: {
    node: true,
    browser: true,
    'jest/globals': true
  },
  settings: {
    es: { aggressive: true }
  },
  globals: {
    Promise: true
  }
};

Any advice?

Invitation to move to official `eslint-community` org

We would love to have this repo added to the official @eslint-community organization on GitHub.

As you can read in the '@eslint-community GitHub organization' RFC, the goal of this new org is to have a place where community members can help ensure widely depended upon ESLint related packages stay up to date with newer ESLint releases and doesn't hold the wider community back without depending on one person's GitHub/npm account.

Since this plugin is really popular (1M+ download/week) & since it's currently unmaintained (the latest commit is almost 2y old & the latest interaction is almost 2y old as well), we'd love you β€”@mysticateaβ€” to transfer this repo to a better home, so you're welcome to transfer this repository to the new org.

Feature request: Add config for typescript

Hello,

Thank you for the plugin.

I am using typescript with target=ES2017 option.

If I have:

const y = { ...x };
const re = /(?<!a)b/u;

It is transpiled:

const y = Object.assign({}, x);
const re = /(?<!a)b/u;

So, with typescript I can use spread operator, but not regexp lookback.
Your restrict-to-es2017 does not catch this.

My suggestion is to add configs for typescript that should disallow those features that are missing in respective ES version and not transpiled by typescript.

I think that typescript configs should include only regexp-related rules, but not sure.

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.