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.

curly: Allow to filter affected keywords and pass keywords-exceptions

See original GitHub issue

JSCS has rules disallowCurlyBraces and requireCurlyBraces that allows to pass keywords: ["if", "else", "for", "while", "do", "try", "catch", "default"].

More over requireCurlyBraces has allExcept option that works like exception for passed keywords:

    - `'allExcept'`
        - Array of keywords inside of the block that would allow curly braces
        - Ex: ["return" , "continue", "break"]

E.g. for:

"allExcept": ["return", "continue", "break"]

it works like:

// Here we need curlies
if (true) {
  // Dummy
} else {
  // Another one
}

// And here we don't
if (true) return false;
else if (false) break;
else continue;

The current curly options and the first suggestion:

"curly": [2, "all"]
"curly": [2, "multi"]
"curly": [2, "multi-line"]
"curly": [2, "multi-or-nest"]
"curly": [2, "multi", "consistent"]

I suggest to pass an Object with keywords and exceptions as the last parameter:

"curly": [2, { "keywords": ["if", "else"], "except": ["return", "break"] }]
"curly": [2, "multi", { "keywords": … }]
// or even:
"curly": [2, { "schema": "multi", "consistent": true, "keywords": … }]

Related: https://github.com/eslint/eslint/issues/4007

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, May 3, 2016

Some ESLint’s rules have overrides option: keyword-spacing, space-unary-ops, and operator-linebreak. So, how about the overrides option for consistency?

For example:

{
    "curly": [2, {
        "type": "all",
        "overrides": {
            "if": {"type": "multi"}
        }
    }]
}
1reaction
aladdin-addcommented, Dec 2, 2017

I’m willing to implement this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception Handling in Spring MVC
Exceptions thrown outside the Spring MVC framework, such as from a servlet Filter, are still reported by the Spring Boot fallback error page ......
Read more >
Exceptional C# Exception Filtering - Pluralsight
The exception handling features of C# help you deal with unexpected or exceptional situations with three keywords: "try", "catch", ...
Read more >
Query and filter context | Elasticsearch Guide [8.5] | Elastic
Use query clauses in query context for conditions which should affect the score of matching documents (i.e. how well does the document match),...
Read more >
Robot Framework User Guide
If keyword needs to accept and pass forward any named arguments, it must be changed to accept free named arguments. See free named...
Read more >
Template Designer Documentation - Jinja
Filters that accept arguments have parentheses around the arguments, ... All unconsumed keyword arguments are stored in this special variable.
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