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

'ImportDeclaration': 'never', is not enforced. #14024

Closed
TheDutchCoder opened this issue Jan 21, 2021 · 9 comments · Fixed by #14063
Closed

'ImportDeclaration': 'never', is not enforced. #14024

TheDutchCoder opened this issue Jan 21, 2021 · 9 comments · Fixed by #14063
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation rule Relates to ESLint's core rules
Projects

Comments

@TheDutchCoder
Copy link

Tell us about your environment

  • ESLint Version: 6.7.2
  • Node Version: 12.19.0
  • npm Version: 6.14.10

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?
default

Please show your full configuration:

Configuration
module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    'plugin:vue/vue3-recommended',
    '@vue/typescript/recommended',
  ],
  parserOptions: {
    ecmaVersion: 2020,
  },
  ignorePatterns: ['**/models/*.*'],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    '@typescript-eslint/indent': [
      'error',
      2,
    ],
    '@typescript-eslint/ban-ts-ignore': 0,
    'linebreak-style': [
      'error',
      'unix',
    ],
    'quotes': [
      'error',
      'single', {
        'allowTemplateLiterals': true,
      },
    ],
    'semi': [
      'error',
      'never',
    ],
    'space-before-function-paren': [
      'error',
      'always',
    ],
    'object-curly-spacing': [
      'error',
      'always',
    ],
    'object-curly-newline': ['error', {
      'ObjectExpression': 'always',
      'ObjectPattern': { 'multiline': true },
      'ImportDeclaration': 'never',
      'ExportDeclaration': { 'multiline': true, 'minProperties': 2 }
    }],
    'comma-dangle': [
      'error',
      {
        'arrays': 'always-multiline',
        'objects': 'always-multiline',
        'imports': 'always-multiline',
        'exports': 'always-multiline',
        'functions': 'never',
      },
    ],
  },
  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)',
      ],
      env: {
        jest: 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.

This is in a .vue SFC, within the script tag.

import { defineComponent, ref,
  PropType } from 'vue'

ESlint is ran from within VSCode.

What did you expect to happen?
The import to not allow line breaks, because 'ImportDeclaration': 'never', is set.

What actually happened? Please include the actual, raw output from ESLint.
Line breaks aren't throwing an error.

Are you willing to submit a pull request to fix this bug?
I have no knowledge of eslint internals, but sure, if I can help, more than willing to!

@TheDutchCoder TheDutchCoder added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jan 21, 2021
@TheDutchCoder
Copy link
Author

TheDutchCoder commented Jan 21, 2021

Please note that the docs are very explicit about what is supposed to happen here:
"never" disallows line breaks inside braces

And there's definitively a line break between these braces:

import { defineComponent, ref, // looks like a line break to me!
  PropType } from 'vue'

@mdjermanovic mdjermanovic added works as intended The behavior described in this issue is working correctly and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jan 22, 2021
@mdjermanovic
Copy link
Member

Hi @TheDutchCoder, thanks for the issue!

This rule enforces linebreaks after { and before }.

In this case, it works as intended, since there's no linebreak between { and defineComponent, and there's no linebreak between PropType and }.

There are examples of correct code for this rule with the "never" option with linebreaks inside but not after { and before }:

/*eslint object-curly-newline: ["error", "never"]*/

let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

@TheDutchCoder
Copy link
Author

Thanks for replying!

The rule clearly says "inside" braces, so maybe the output is intended, but then the description of the rule is incorrect.

Regardless, what would be the rule to make sure no line breaks are allowed, well, inside the braces? ;)

@mdjermanovic
Copy link
Member

The rule clearly says "inside" braces, so maybe the output is intended, but then the description of the rule is incorrect.

I agree that the wording isn't clear, a PR to clarify this would be welcome!

Regardless, what would be the rule to make sure no line breaks are allowed, well, inside the braces? ;)

We don't have a rule to disallow linebreaks inside braces of named imports in the core set of rules. Given our rules policies, I think the best course of action would be to create a custom rule or a plugin.

@arminyahya
Copy link
Contributor

@TheDutchCoder did you start writing a custom rule for this? I'll be happy to try.
can i change object-curly-newline docs for this issue?

@mdjermanovic
Copy link
Member

can i change object-curly-newline docs for this issue?

Yes, I think it's a good idea to clarify what "inside braces" means for this rule, or to reword it.

@arminyahya
Copy link
Contributor

@mdjermanovic

Isn't better to replace inside braces with for braces?

sentences change like this:

"always" requires line break for braces.

@mdjermanovic
Copy link
Member

I think it would be best to say "after" and "before", like in rule details of array-bracket-newline.

@arminyahya
Copy link
Contributor

I'm going to do this, give me one day.

arminyahya added a commit to arminyahya/eslint that referenced this issue Feb 2, 2021
arminyahya added a commit to arminyahya/eslint that referenced this issue Feb 2, 2021
@nzakas nzakas added the documentation Relates to ESLint's documentation label Feb 9, 2021
@nzakas nzakas added this to Ready to Implement in Triage Feb 9, 2021
@mdjermanovic mdjermanovic linked a pull request Feb 10, 2021 that will close this issue
9 tasks
@mdjermanovic mdjermanovic moved this from Ready to Implement to Pull Request Opened in Triage Feb 10, 2021
@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed works as intended The behavior described in this issue is working correctly labels Feb 16, 2021
@mdjermanovic mdjermanovic added the rule Relates to ESLint's core rules label Mar 12, 2021
Triage automation moved this from Pull Request Opened to Complete Mar 24, 2021
mdjermanovic pushed a commit that referenced this issue Mar 24, 2021
* Docs: Clarify line breaks in object-curly-newline (refs #14024)

* Docs: Clarify line breaks in object-curly-newline (refs #14024)

* Fix: Clarify line breaks in object-curly-newline (fixes #14024)
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Sep 21, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation rule Relates to ESLint's core rules
Projects
No open projects
Triage
Complete
Development

Successfully merging a pull request may close this issue.

4 participants