question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

padding-line-between-statements: Missing functionality covered by deprecated lines-around-directive

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.9.0
  • Node Version: 10.13.0
  • npm Version: 6.4.1

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

Please show your full configuration:

Configuration
module.exports = {
  rules: {
    'lines-around-directive': ['error', { before: 'never', after: 'always' }],

    'padding-line-between-statements': ['error',
      { blankLine: 'never', prev: '*', next: 'directive' },
      { blankLine: 'always', prev: 'directive', next: '*' },
    ],
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

<empty line>
'use strict';

console.log(1);

also

/**
 * Copyright
 */

'use strict';

console.log(1);

command:

eslint .

What did you expect to happen?

Both the lines-around-directive (deprecated) rule and padding-line-between-statements rules should warn about the unexpected empty line at the start of the file.

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

Only the lines-around-directive rule produced an error:

  2:1  error  Unexpected newline before "use strict" directive  lines-around-directive

Are you willing to submit a pull request to fix this bug?

Maybe. The hard part here is figuring out what to do about this.


The problem seems to be that prev: '*' in the padding-line-between-statements configuration doesn’t match the top of the file before the 'use strict'; directive.

This is a real problem because the lines-around-directive rule was deprecated in ESLint v4.0.0 with the claim that it will be replaced by the padding-line-between-statements rule. However, the padding-line-between-statements rule is not able to fully replicate the functionality of the lines-around-directive rule because of this bug.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

5reactions
kaicataldocommented, Sep 29, 2019

One other thought: we currently have padded-blocks, lines-around-comment, lines-between-class-members, and padding-line-around-statements.

Could we deprecate padding-line-around-statements, lines-around-comment, and lines-between-class-members in favor of a new rule padding-lines that allows for the enforcement of padding lines between any syntax in the same scope (including statements, properties, methods, comments, directives - everything!). It could essentially have the same API and configuration options it does now with the addition of options needed to cover the cases from the other rules.

We can then deprecate padded-blocks in favor of a new rule called padded-scope that covers all that padded-blocks currently does, but also covers the file/module scope (and therefore cover BOF and EOF).

This way, we could have two padding line rules - one for padding lines between syntax in the same scope and one for padding lines within new scopes (including the file/module scope).

I know our padding lines rules have changed a lot over the years, but I don’t know how useful it is to have multiple rules for different syntax, and I think having two more generic, highly configurable rules could allow for users to have more control over this.

If the team is amenable to this, I can do some more research and write up a formal proposal.

1reaction
IgorNovozhilovcommented, Sep 26, 2019

@nwoltman, @kaicataldo. I check this on v.6.4.0 no-multiple-empty-lines is worked now in this situation example:

    'no-multiple-empty-lines': ['warn',
      { max: 2, maxEOF: 0, maxBOF: 0 }
    ],
    1:1  warning  Too many blank lines at the beginning of file. Max of 0 allowed  no-multiple-empty-lines
  336:1  warning  Too many blank lines at the end of file. Max of 0 allowed        no-multiple-empty-lines

✖ 2 problems (0 errors, 2 warnings)
  0 errors and 2 warnings potentially fixable with the `--fix` option.

ps: no-multiple-empty-lines - Allows \n on the last line, and does not conflict with eol-last

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint/CHANGELOG.md - UNPKG
47, * f026fe1 Update: Fix 'function' in padding-line-between-statements (fixes ... 179, * f7330c1 Chore: Add ESLint path to plugin-missing message (#10283) ...
Read more >
Code Issues - Embold Help Center
If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.
Read more >
eslint-config-canonical - npm
Rule CN AB GG SD XO @babel/new‑cap ❌ 👻 👻 👻 👻 @babel/no‑invalid‑this 🚨 👻 👻 👻 👻 @babel/no‑unused‑expressions 🚨 👻 👻 👻 👻
Read more >
node_modules/eslint/CHANGELOG.md · master - PLMlab
39dfe08 Update: false positives in function-call-argument-newline ... add missing deprecation notices for jsdoc rules (#11171) (Teddy Katz).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found