Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check that the range param is not undefined #13540

Conversation

JesuHrz
Copy link

@JesuHrz JesuHrz commented Jul 30, 2020

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This PR resolved the next issue:

When I add this option "parser": "babel-eslint" in my .eslintrc file but I also have this rules "indent": ["error", 2] or some other implementation of this rule and I want to run eslint . or eslint . --fix.

The terminal gave us this error:

image

This error only happens when I have these options in my .eslintrc file.

When adding this validation in this setDesiredOffsets function and I run some of these options eslint . or eslint . --fix, the eslint output is completed without any problem

Note:

if any of you have some feedback or a better solution, please let me know.

Is there anything you'd like reviewers to focus on?

Tell us about your environment

  • ESLint Version: v7.5.0
  • Node Version: v14.0.0
  • npm Version: v6.14.4

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

I'm using this parser babel-eslint with the version v10.1.0

Please show your full configuration:

Configuration
{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module",
    "allowImportExportEverywhere": true,
    "ecmaFeatures": {
      "impliedStrict": true
    }
  },
  "extends": ["eslint:recommended"],
  "rules": {
    "no-unexpected-multiline": "off",
    "no-else-return": ["error", { "allowElseIf": true }],
    "no-async-promise-executor": "off",
    "no-trailing-spaces": "error",
    "space-infix-ops": "error",
    "computed-property-spacing": "error",
    "space-before-function-paren": "error",
    "arrow-spacing": "error",
    "no-multi-spaces": "error",
    "eol-last": ["error", "always"],
    "comma-dangle": ["error", "never"],
    "space-before-blocks": ["error", "always"],
    "space-in-parens": ["error", "never"],
    "comma-spacing": ["error", { "before": false, "after": true }],
    "key-spacing": ["error", { "beforeColon": false }],
    "semi": ["error", "always"],
    "quotes": ["error", "single"],
    "object-curly-spacing": ["error", "always"],
    "array-bracket-spacing": ["error", "never"],
    "prefer-const": "error",
    "no-path-concat": "error",
    "no-unused-vars": ["error", { "args": "none" }],
    "camelcase": "error",
    "no-var": "error",
    "one-var": ["error", "never"],
    "spaced-comment": ["error", "always"],
    "padding-line-between-statements": [
      "error",
      {
        "blankLine": "always",
        "prev":  ["const", "let", "var"],
        "next": "function"
      }
    ],
    "no-tabs": "error",
    "indent": ["error", 2],
    "max-len": [
      "error",
      {
        "code": 80,
        "ignoreRegExpLiterals": true,
        "ignoreUrls": true,
        "tabWidth": 2
      }
    ]
  },
  "env": {
    "node": true,
    "browser": true,
    "es2017": true
  }
}

What did you do? Please include the actual source code causing the issue.

This error happens when I have this configuration and run eslint . or eslint . --fix.

Code
import camelCase from './camelCase'

class Router {
  constructor ({ routes, common }) {
    this.routes = routes
    this.common = common
  }

  fire (chunk) {
    if (typeof chunk === 'undefined') {
      console.error(
        "Failed to execute 'fire': " +
        'The 1 parameter is required, but it was not present.'
      )
      return
    }

    if (typeof chunk !== 'string') {
      console.error(
        "Failed to execute 'fire': " +
        'The 1 parameter must be string.'
      )
      return
    }

    const chunkFile = this.routes[chunk]

    if (chunkFile) {
      if (Array.isArray(this.common)) {
        this.common.map((module) => {
          import(/* webpackChunkName: "common" */ `../routes/${module}`)
            .then(module => module.default())
            .catch(e => console.warn(e))
        })
      }
      if (typeof this.common === 'string') {
        import(/* webpackChunkName: "common" */ `../routes/${this.common}`)
          .then(module => module.default())
          .catch(e => console.warn(e))
      }
      import(/* webpackChunkName: "chunk" */ `../routes/${chunkFile}`)
        .then(module => module.default())
        .catch(e => console.warn(e))
    }
  }

  loadEvents () {
    document.body.className
      .toLowerCase()
      .replace(/-/g, '_')
      .split(/\s+/)
      .map(camelCase)
      .forEach(className => this.fire(className))
  }
}

export default Router

What did you expect to happen?

I expected the eslint output was completed with my code indented

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

image

@jsf-clabot
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jul 30, 2020
@JesuHrz JesuHrz changed the title fix: check that the Range is not undefined fix: check that the range param is not undefined Jul 30, 2020
@mdjermanovic mdjermanovic added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jul 30, 2020
@mdjermanovic
Copy link
Member

Hi @JesuHrz, thanks for the PR!

Could you please fill out the bug report template?

I believe this might be a known bug in babel-eslint, but can't tell without the source code causing the issue.

@JesuHrz JesuHrz closed this Jul 30, 2020
@JesuHrz
Copy link
Author

JesuHrz commented Jul 30, 2020

Hi @mdjermanovic, sorry I accidentally closed the PR, but I was able to open it again.
Besides, I already completed the bug report template and if you any feedback please let me know it

@JesuHrz JesuHrz reopened this Jul 30, 2020
@mdjermanovic
Copy link
Member

Thanks!

Could you please also paste the source code (Router.js or some minimal code where it also crashes if you can't share the actual source code) in the "What did you do? Please include the actual source code causing the issue." section?

This will helps us with reproducing the bug and finding the cause.

@JesuHrz
Copy link
Author

JesuHrz commented Jul 31, 2020

Of course, not problem @mdjermanovic, it already is updated

@mdjermanovic
Copy link
Member

Hm, I still can't see it.

Sorry if it wasn't clear - we need the content of the file that was linted (Router.js in this case) to reproduce the bug and then find out what's causing it.

If you can't share the whole file (which would be ideal), a small part would do the work if the bug is reproducible on it.

It looks like this is crashing on a template literal in your code, and I'd guess it's a code like import(`...`).

@JesuHrz
Copy link
Author

JesuHrz commented Jul 31, 2020

I just updated the code, it's already complete. @mdjermanovic

I think the mistake comes from the first line import camelCase from './camelCase'

@mdjermanovic
Copy link
Member

Thanks for all details! I can reproduce this bug.

The issue is with dynamic imports; when I comment out all three, then it doesn't crash.

A minimal code to reproduce the error:

import(/* webpackChunkName: "common" */ `../routes/${module}`)

This is a bug in babel-eslint, it works fine with the default parser.

babel/babel-eslint#799

babel/babel#10904

We shouldn't change the indent rule because this change would hide the real bug in the parser, and the rule wouldn't work as intended.

This will be fixed in the next version of babel-eslint (which will be @babel/eslint-parser, see babel/babel#10752).

@mdjermanovic mdjermanovic added the 3rd party plugin This is an issue related to a 3rd party plugin, config, or parser label Jul 31, 2020
@JesuHrz
Copy link
Author

JesuHrz commented Jul 31, 2020

Ohh great!!
thanks for your feedback @mdjermanovic 👍

@mdjermanovic mdjermanovic removed the evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion label Jul 31, 2020
@mdjermanovic
Copy link
Member

I'm closing this since it isn't a bug in the indent rule.

It's a known bug in babel-eslint (babel/babel#10904) which affects several rules, and it isn't reproducible with ESLint's default parser.

The bug should be fixed in the next version, under the new package name @babel/eslint-parser (please see here for more information). If it happens that the bug isn't fixed in @babel/eslint-parser, please make an issue in https://github.com/babel/babel repository.

Nevertheless, thanks for the PR!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 4, 2021
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd party plugin This is an issue related to a 3rd party plugin, config, or parser archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants