Coder Social home page Coder Social logo

eslint-no-inferred-method-name's People

Contributors

dependabot[bot] avatar ericelliott avatar johnstonbl01 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

Watchers

 avatar  avatar  avatar

eslint-no-inferred-method-name's Issues

Documentation incorrect

[Edit: clarified and adjusted tone of my wording]

"Every form of function expression assignment in ES6 infers a name that can be used inside the function for recursion."

That statement is false. The function name inference has nothing to do with the ability to make lexical name recursive calls. The inference is assigning a name property to the function object, not giving the function object a named binding in the surrounding (or owned) lexical environment (which would be required for recursion).

The code snippet also reinforces this incorrect information:

return foo(f, i); // foo is inferred within the compact object literal

That foo(f,i) call will be an error, as there will not be a foo lexical identifier referencing the function. There is no such thing as inferring a lexical name. The foo lexical name will exist at that line of code, but it'll be pointing to the foo object (not function) declared on the first line of the snippet. As such, a TypeError will be thrown because you're trying to call a non-function value.

Concise methods do not have lexical name bindings and thus such a lexical name cannot be used, being that it doesn't exist, for recursion or any other self-referential purpose.

TypeError: Cannot read property 'type' of null

The following line:

myPromise.then(doSomething)

Generates the following error in ESLint:

[Error - 11:23:34 AM] ESLint stack trace: [Error - 11:23:34 AM] TypeError: Cannot read property 'type' of null Occurred while linting /myapp/script.js:2 at /myapp/node_modules/eslint-plugin-no-inferred-method-name/lib/rules/no-inferred-method-name.js:40:51 at Array.forEach (<anonymous>) at Program:exit (/myapp/node_modules/eslint-plugin-no-inferred-method-name/lib/rules/no-inferred-method-name.js:37:29) at /myapp/node_modules/eslint/lib/linter/safe-emitter.js:45:58 at Array.forEach (<anonymous>) at Object.emit (/myapp/node_modules/eslint/lib/linter/safe-emitter.js:45:38) at NodeEventGenerator.applySelector (/myapp/node_modules/eslint/lib/linter/node-event-generator.js:254:26) at NodeEventGenerator.applySelectors (/myapp/node_modules/eslint/lib/linter/node-event-generator.js:283:22) at NodeEventGenerator.leaveNode (/myapp/node_modules/eslint/lib/linter/node-event-generator.js:306:14) at CodePathAnalyzer.leaveNode (/myapp/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:655:23)

Missing check for compact method name

The real issue is with compact object literals. Here's the example we need to fix:

const repeater = {
  name: 'Repeater',
  types: [
    { f: 'function' },
    { n: 'number' }
  ],
  repeat (f, n) {
    let i = n - 1;

    if (typeof f === 'function') {
      f();
    } else {
      throw new Error('repeat: A Function is required.');
    }
    if (!n) {
      return undefined;
    }

    return repeat(f, i);
  }
};

repeater.repeat(() => {console.log('foo');}, 10);

Results:

foo
ReferenceError: repeat is not defined

The way to fix that is to report an error when the method name is used within the function, because inside the function, the method name is undefined. The error should be reported for this line:

    return repeat(f, i);

The built-in no-undef rule already catches this error, but we need to explicitly tell the user that compact method names are not available inside the method in order to clear up any confusion.

Possible to install as a plugin?

Is it possible to install this rule as an eslint plugin so you don't have to copy the file into the rules directory? That would significantly enhance the install experience.

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.