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

Rule Proposal: lines-around-directive #6069

Closed
mysticatea opened this issue May 4, 2016 · 14 comments
Closed

Rule Proposal: lines-around-directive #6069

mysticatea opened this issue May 4, 2016 · 14 comments
Assignees
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

mysticatea commented May 4, 2016

From requirePaddingNewLinesAfterUseStrict and disallowPaddingNewLinesAfterUseStrict.

This rule will require/disallow blank lines before/after a chunk of directive prologues.

{
    "lines-around-directive": ["error", "always" or "never"],
    // or
    "lines-around-directive": ["error", {
        "after": "always" or "never",
        "before": "always" or "never"
    }]
}

Valid:

/*eslint lines-around-directive: ["error", "always"]*/

// header comment?

"use strict";

foo();

function foo() {
    "use strict";  // ignore at the head of block. this is warned by padded-blocks.
    "use asm";     // ignore between directives.

    foo();
}
/*eslint lines-around-directive: ["error", "never"]*/

// header comment?
"use strict";
foo();

function foo() {

    "use strict";  // ignore at the head of block. this is warned by padded-blocks.
    "use asm";     // ignore between directives.
    foo();
}

Invalid:

/*eslint lines-around-directive: ["error", "always"]*/

// header comment?
"use strict";
foo();

function foo() {
    "use strict";
    foo();
}
/*eslint lines-around-directive: ["error", "never"]*/

// header comment?

"use strict";

foo();

function foo() {
    "use strict";

    foo();
}
@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 4, 2016
@mysticatea mysticatea added this to the JSCS Compatibility milestone May 4, 2016
@mysticatea
Copy link
Member Author

Can we check lines between Shebang and directive prologues?

@ilyavolodin
Copy link
Member

@mysticatea We should be able to, since shebang is commented out before parsing, we just have to check comment value.

@nzakas
Copy link
Member

nzakas commented Jul 21, 2016

Do we need to check padding before? That would almost always be covered by padded-blocks, wouldn't it?

@mysticatea
Copy link
Member Author

I had imaged the previous padding for shebang and header comment.

#!/usr/bin/env node

"use strict"
/**
 * header comment
 */

"use strict"

@nzakas
Copy link
Member

nzakas commented Jul 22, 2016

I see. So then this rule's before would not apply in blocks?

@mysticatea
Copy link
Member Author

/*eslint lines-around-directives*/

function a() {
    "use strict";
}

function a() {

    "use strict";
}

function a() {
    /*
     * comment
     */

    "use strict";
}

@mysticatea
Copy link
Member Author

mysticatea commented Jul 22, 2016

Sorry, I clicked a wrong button...

I'm thinking before would apply if there is a comment at the top of blocks.

@nzakas
Copy link
Member

nzakas commented Jul 22, 2016

Doesn't padded-blocks already cover that case, too?

@mysticatea
Copy link
Member Author

padded-blocks checks lines before the top comment in the block.

function foo() {
    <!-- by padded-blocks -->
    /*COMMENT*/
    <!-- by lines-around-directives -->
    "use strict";
    <!-- by lines-around-directives -->
    doSomething()
    <!-- by padded-blocks -->
}

@nzakas
Copy link
Member

nzakas commented Jul 25, 2016

Ah, I see. Got it.

👍

@kaicataldo
Copy link
Member

kaicataldo commented Aug 3, 2016

Anything else left to discuss here? I'm happy to champion this one. I'm looking for a JSCS compat issue to work on this weekend and this seems like a good one :)

@eslint/eslint-team thoughts?

@platinumazure
Copy link
Member

👍 from me.

@alberto
Copy link
Member

alberto commented Aug 3, 2016

👍

@alberto alberto added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 3, 2016
@mikesherov
Copy link
Contributor

👍

@nzakas nzakas closed this as completed in c1f0d76 Aug 30, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
No open projects
Development

No branches or pull requests

7 participants