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.

`'padded-blocks': ['error', 'never']` doesn't appear to disallow padding in ES6 `class` declarations

See original GitHub issue

Tell us about your environment NodeJS (literally just index.js, package.json, and a node_modules folder).

  • ESLint Version: v3.12.2
  • Node Version: v6.9.2
  • npm Version: 3.10.9

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

Please show your full configuration:

'use strict';

const ESLintConfiguration = {
	root: true,
	parserOptions: {
		sourceType: 'script'
	},
	env: {
		es6: true,
		node: true
	},
	rules: {
		'padded-blocks': ['error', 'never']
	}
}

module.exports = ESLintConfiguration;

What did you do? Please include the actual source code causing the issue. Linted this file:

'use strict';

class SomeClass {

	constructor(opts) {

		this.opts = opts;

	}

}

const instance = new SomeClass(12);

console.log(instance.opts);

Specifically, I ran this command:

`npm bin`/eslint index.js

What did you expect to happen?

/Users/treybrisbane/src/personal/eslint-test/index.js
  3:17  error  Block must not be padded by blank lines  padded-blocks
  5:20  error  Block must not be padded by blank lines  padded-blocks
  9:2   error  Block must not be padded by blank lines  padded-blocks
  11:1  error  Block must not be padded by blank lines  padded-blocks

✖ 4 problems (4 errors, 0 warnings)

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

/Users/treybrisbane/src/personal/eslint-test/index.js
  5:20  error  Block must not be padded by blank lines  padded-blocks
  9:2   error  Block must not be padded by blank lines  padded-blocks

✖ 2 problems (2 errors, 0 warnings)

Interestingly, if I use this configuration (note the more specific padded-blocks options)…

'use strict';

const ESLintConfiguration = {
	root: true,
	parserOptions: {
		sourceType: 'script'
	},
	env: {
		es6: true,
		node: true
	},
	rules: {
		'padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }]
	}
}

module.exports = ESLintConfiguration;

… I get the expected output.

It seems as though simply supplying 'never' to padded-blocks does NOT set classes: 'never', but DOES set blocks: 'never' (what about switches?). This may be a documentation oversight, but if this is intended behaviour, it seems a bit unintuitive!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jan 6, 2017

@alberto Do you think we could change the default behavior in a major release? I think this is probably a bit confusing as is.

0reactions
treybrisbanecommented, Jan 7, 2017

Thanks for the clarification, guys. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

padded-blocks - ESLint - Pluggable JavaScript Linter
"never" disallows empty lines at the beginning and ending of block statements, function bodies, class static blocks, classes, and switch statements.
Read more >
Eslint configuration for padded-blocks and lines-around ...
Seems like these rules are opposite to each other at starting of class. How can I ignore padded-blocks rule for constructor named function...
Read more >
tslint-eslint-rules - npm
ESLint rules for TSLint. Improve your TSLint with the missing ESLint Rules. You want to code in TypeScript but miss all the rules...
Read more >
Low level issues - Embold Help Center
no -empty, Empty block statements, while not technically errors, usually occur due to refactoring that wasn't completed. They can cause confusion when ...
Read more >
in javascript, which keyword used in variable declarations limits its ...
ES6 introduced two important new JavaScript keywords: let and const. ... Variables declared with the var keyword can NOT have block scope.
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