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

eslint-disable / eslint-enable still tries to parse content between comments #5005

Closed
whomba opened this issue Jan 19, 2016 · 11 comments

Comments

Projects
None yet
6 participants
@whomba
Copy link

commented Jan 19, 2016

When an error occurs that you do not care about (such as ESLint thinking a Ruby include should be rendered as JS) the use of:

<% extend ActionView::Helpers::JavaScriptHelper %> // eslint-disable-line

and

/* eslint-disable */
  <% extend ActionView::Helpers::JavaScriptHelper %>
/* eslint-enable */

This still causes an error to happen, ESLint is still executing this code

Version
v1.10.3

What I did:

  • Created a new .eslintrc.json from the eslint --init tool
  • Executed: eslint -c .eslintrc.json myFile.js.erb --ext .js,.es6,.jsx,.erb
  • contents of myFile.js.erb:
<% extend ActionView::Helpers::JavaScriptHelper %>

Output from ESLint:

myFile.js.erb
  1:3  error  Parsing error: Unexpected token

What I expected to happen:
I would have expected this to pass without an issue as the problematic line has been commented out.

@eslintbot

This comment has been minimized.

Copy link

commented Jan 19, 2016

@whomba Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage label Jan 19, 2016

@whomba

This comment has been minimized.

Copy link
Author

commented Jan 19, 2016

@eslintbot my apologies, this has been updated

@platinumazure

This comment has been minimized.

Copy link
Member

commented Jan 20, 2016

Yeah, the whole file will be parsed anyway before ESLint comments are taken into account. What you need is a plugin that will preprocess .ejs files which will return only the JavaScript, before parsing and linting.

Do a search on npm to see if there is a plugin for .ejs files.

@whomba

This comment has been minimized.

Copy link
Author

commented Jan 20, 2016

@platinumazure Ah, ok, that makes sense. I think the documentation should be updated to specify that this only applies to rules to avoid any confusions from people coming from the jshint world.

@platinumazure

This comment has been minimized.

Copy link
Member

commented Jan 20, 2016

@whomba Sounds good- want to write up a PR?

@btmills

This comment has been minimized.

Copy link
Member

commented Jan 30, 2016

Working on this.

@btmills btmills self-assigned this Jan 30, 2016

ilyavolodin added a commit that referenced this issue Jan 31, 2016

Merge pull request #5109 from eslint/issue5005
Docs: Clarify eslint-disable comments only affect rules (fixes #5005)
@akashnimare

This comment has been minimized.

Copy link

commented Jun 21, 2017

I'm getting the same error on -

if (true) {
	console.log("true");
        return;
}

Is there any workaround for this? Is there any way I can disable Parsing error: return outside of function ?
cc @btmills, @ilyavolodin

@platinumazure

This comment has been minimized.

Copy link
Member

commented Jun 21, 2017

@akashnimare This is a different issue. Take a look at the parser options you can specify in configuration-- basically you need to avoid sourceType: module and possibly add globalReturn: true, if you're using the default parser. If that doesn't work, please open a new issue or stop by our Gitter chat.

@akashnimare

This comment has been minimized.

Copy link

commented Jun 21, 2017

@platinumazure thanks. I'm using XO. My config file is -

 "xo": {
    "esnext": true,
    "overrides": [
      {
        "files": "app*/**/*.js",
        "rules": {
          "max-lines": [
            "warn",
            500
          ],
          "no-warning-comments": 0,
          "capitalized-comments": 0,
          "no-else-return": 0,
          "no-path-concat": 0,
          "no-alert": 0,
          "guard-for-in": 0,
          "prefer-promise-reject-errors": 0,
          "import/no-unresolved": 0,
          "import/no-extraneous-dependencies": 0
        }
      }
    ],
    "ignore": [
      "tests/*.js"
    ],
    "envs": [
      "node",
      "browser",
      "mocha"
    ]
  }
@platinumazure

This comment has been minimized.

Copy link
Member

commented Jun 21, 2017

@akashnimare I guess you didn't see my note about opening a new issue for your case since your issue is unrelated to this issue. 😄 If you're using eslint-plugin-import then you are probably using sourceType: module, so global return is forbidden in espree for ES6 modules. It's not valid JavaScript.

@akashnimare

This comment has been minimized.

Copy link

commented Jun 21, 2017

My bad, I'll open a new issue. Thanks for explaining :)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.