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
New: lines-around-directive
rule (fixes #6069)
#6998
Conversation
@kaicataldo, thanks for your PR! By analyzing the annotation information on this pull request, we identified @nzakas, @alberto and @mysticatea to be potential reviewers |
8d42ee4
to
d59f67d
Compare
LGTM |
Thank you for implementation! My intention was that this rule handles directive prologues (not restrict
A directive prologue might be multiline:
|
Ah, okay. So to check each directive in the prologue I could maybe do something like this (to borrow this implementation) function getDirectives(statements) {
const directives = [];
for (let i = 0; i < statements.length; i++) {
const statement = statements[i];
if (
statement.type === "ExpressionStatement" &&
statement.expression.type === "Literal"
) {
directives[i] = statement;
} else {
break;
}
}
return directives;
} Adding do not merge label until I update this. |
Thank you. By the way, |
You're right! Do you mean adding a |
Yes! |
Got it working for multiple directives and then realized I wasn't sure if we want to check each directive individually or if we want to check around the entire directive prologue. Any thoughts on this @mysticatea? Now that I know we're checking all directives, I think it makes sense to have an option to enforce blank newlines around the whole prologue (as a group). This wasn't discussed in the accepted issue though, so maybe we should talk about it there. |
Actually, my first post #6069 says "ignores between directives". |
Ah, so it does...Missed that somehow. Okay, thanks! Will update accordingly 👍 |
Still have to update the docs |
e45a5fa
to
66d9821
Compare
Updated with new docs. Please let me know what you think, @mysticatea. Thanks for helping with this! |
4ab5b1a
to
6aade1c
Compare
LGTM |
Wow, there are super many tests! |
directives.push(statement); | ||
} else { | ||
if (!directives.length) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I prefer an empty array instead of null
.
(currently, this returns an empty array if the function is empty?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would your preference be for it to return an empty array for the early return as well? My goal was to make it consistent for when it doesn't find directives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is that the function always returns an array. We can check the existence of directive prologues by the length
of the result (or by iteration of the result).
Also, current implementation seems inconsistent.
// In empty function case, returns `[]`
function foo() {
}
// In non-strict function case, returns `null`
function foo() {
bar()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return null
in both cases (https://github.com/eslint/eslint/pull/6998/files#diff-6198b73cda8ab9ac49ed872ead7fb268R716), but I can definitely make it always return an array 👍
LGTM |
Updated once more |
Great, thank you very much! |
@@ -0,0 +1,320 @@ | |||
# Require or disallow newlines around directives (lines-around-directive) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are doing lowercase first word now.
Lgtm, just one tiny thing on the docs. Really nice job on this -- I especially love the intro on the docs. Very well-written. 💯 |
54713c7
to
383f2c4
Compare
LGTM |
Super awesome, @kaicataldo!! Great job! 🎉 🎉 |
No description provided.