Git Product home page Git Product logo

eslint-utils's Introduction

eslint-utils

npm version Downloads/month Build Status Coverage Status Dependency Status

🏁 Goal

This package provides utility functions and classes for make ESLint custom rules.

For examples:

πŸ“– Usage

See documentation.

πŸ“° 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 lint runs ESLint.
  • npm run watch runs tests on each file change.

eslint-utils's People

Contributors

fisker avatar michaeldeboey avatar mysticatea avatar ninevra avatar ota-meshi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

eslint-utils's Issues

`getStaticValue` doesn't track references types correctly

Example: const a = []; a === a will evaluate to false.

This is because getStaticValue evaluates each reference to a variable separately, so we get different objects with the same value each time. However, they should be the same value.

Solution: Cache the value of each variable.

Non-solution: Change the === operator (among others) to not evaluate the equality of non-value types. This solution simply doesn't scale as built-in safe functions might use === under the hood.

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 πŸ™‚

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 πŸ™‚

Misleading result from getStaticValue() when called on mutable const-declared variables

When getStaticValue() is called with a scope and encounters an identifier referring to a variable declared with const, it computes that variable's static value based on its const declaration initializer only. If the variable is initialized to a mutable value, it can later be modified, resulting in the return value from getStaticValue() not matching the variable's true value at time of use.

Example:

const mutable = {a: 1};
mutable.b = 2;
mutable;

Calling getStaticValue() on the Identifier node mutable on line 3 returns {value: {a: 1}}, but mutable's actual value is {a: 1, b: 2}.

Minimal working example

This can also result in erroneously identifying identifiers as static. For example:

const mutable = {a: 1};
mutable.b = foo();
mutable;

mutable on line 3 is not static-valued, but getStaticValue() returns {value: {a: 1}}.

Misleading result from getStaticValue() on expressions that re-use Symbol()s

Example:

const symbol = Symbol();
(symbol === symbol); // <--

The value of the expression on line 2 is true, but getStaticValue() returns {value: false}.

This is probably because the two recursive calls to getStaticValueR() (evaluating the left and right sides of the BinaryExpression) both invoke Symbol() and so both return different Symbols.

This could be resolved either by removing Symbol from callAllowed or by caching the static values of Identifiers encountered during recursion. However, the latter approach would still produce strange results if the user compared the returned static values of, for example, two different references to const symbol = Symbol();.

Allow return `symbol` in `getPropertyName`

Currently getPropertyName always return string (bigint is also possible when it's Literal), but property can be a symbol

bar[Symbol.iterator]()

This can be calculated by getStaticValue.

BTW: Similar bug in ESLint core, this will cause foo["Symbol()"] foo[Symbol()] considered as same reference.

I think it should return string | symbol or just return the value as it is, let user convert to string.

Node 13 support?

v3.0.0 of this package supports the following node versions:

"engines": {
    "node": "^10.0.0 || ^12.0.0 || >= 14.0.0"
  },

Why is node 13 ignored/disabled?

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 (31M+ download/week), it's used by the main ESLint repo & since it's currently unmaintained (the latest commit is 1y+ old & the latest interaction is 1y+ 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.

GitHub Security Alert

Remediation
Upgrade eslint-utils to version 1.4.1 or later. For example:

"dependencies": {
"eslint-utils": ">=1.4.1"
}
or…
"devDependencies": {
"eslint-utils": ">=1.4.1"
}
Always verify the validity and compatibility of suggestions with your codebase.

Details
GHSA-3gx7-xhv7-5mx3 More information
critical severity
Vulnerable versions: >= 1.2.0, < 1.4.1
Patched version: 1.4.1
'getStaticValue' function can execute arbitrary code
Impact
getStaticValue function can execute arbitrary code.

Patches
This problem has been patched in 1.4.1. Please update eslint-utils.

Workarounds
Don't use getStaticValue function, getStringIfConstant function, and getPropertyName function.

For more information
If you have any questions or comments about this advisory:

Open an issue in eslint-utils

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.