`padded-blocks`: Add "iife" object option
See original GitHub issueWhat rule do you want to change?
padded-blocks
Does this change cause the rule to produce more or fewer warnings?
Either more or fewer warnings or no change, depending on the configuration.
How will the change be implemented? (New option, new default behavior, etc.)?
A new property to add to the option object, iife
.
Please provide some example code that this change will affect:
Now these will change to produce no warnings:
/* eslint padded-blocks: ["error", {
"blocks": "never",
"iife": "always"
}]*/
(() => {
requirePaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "never",
"iife": "always"
}]*/
(async () => {
await requirePaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "always",
"iife": "never"
}]*/
(() => {
preventPaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "always",
"iife": "never"
}]*/
(async () => {
await preventPaddingHere();
})();
Now these will change to produce new warnings:
/* eslint padded-blocks: ["error", {
"blocks": "always",
"iife": "never"
}]*/
(function () {
preventPaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "always",
"iife": "never"
}]*/
(async function () {
preventPaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "never",
"iife": "always"
}]*/
(() => {
requirePaddingHere();
})();
/* eslint padded-blocks: ["error", {
"blocks": "never",
"iife": "always"
}]*/
(async () => {
await requirePaddingHere();
})();
What does the rule currently do for this code?
Reports an error or fails to report an error.
What will the rule do after it’s changed?
-
If the context is an IIFE and the rule’s existing (string or
blocks
object) option is set to-
“always” (the default behavior of requiring padding), AND the proposed
iife
option is set to “never”-
…there will be Fewer warnings if the IIFE has no padding
-
…there will be More warnings if the IIFE has padding
-
-
“never” (the non-default of disallowing padding) AND the proposed
iife
option is set to “always”-
…there will be Fewer warnings if the IIFE has padding
-
…there will be More warnings if the IIFE has no padding
-
-
-
Under any of these other possibilities, no changes will occur.
-
The context is not an IIFE
-
The user does not use the new
iife
option -
The
iife
option value matches the string orblocks
object option value
-
Are you willing to submit a pull request to implement this change?
Possibly, yes. 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Thanks for all the details!
I support this 👍
So, for an IIFE in the code and the object configuration,
"always"
/"never"
value that applies would be the value set in"iife"
if it’s specified. Otherwise, the value set in"block"
.If
"block"
also isn’t specified, then the IIFE will be ignored, like all other blocks.It could be a bit confusing that
"iife"
, which overrides"block"
, is at the same level in configuration (and would be even more confusing if someone asks to add"function"
), but there is already a precedent of such configuration in thepadding-lines-between-statements
rule.Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.