npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@saji/eslint-plugin-brace-rules

v0.2.1

Published

Enhancements to eslint brace rules

Downloads

1,185

Readme

@saji/eslint-plugin-brace-rules

Enhancements to eslint's default brace-style rules

Originally created by Joshua Searles with modifications by Jason Keimig.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install @saji/eslint-plugin-brace-rules:

$ npm install @saji/eslint-plugin-brace-rules --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install @saji/eslint-plugin-brace-rules globally.

Usage

Add brace-rules to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "@saji/brace-rules"
    ]
}

Then, modify your .eslintrc config with the following updates:

  • Disable the internal brace-style setting
  • Set the default base rule-set that is close to your desired brace-style settings
  • Add only the overrides you need from the list of braceRuleProps

In the example below:

  • All internal brace-style checks are disabled
  • All @saji/brace-rules/brace-on-same-line violations are flagged as errors
  • The baseline brace styling is stroustrup
  • brace on next-line overrides are added for occurances of:
    • class { ... }
    • export class MyClass { ... }
    • export default class MyClass { ... }
    • export default class { ... }
    • export default function { ... }
{
    "rules": {
        ...,
        "brace-style": 0,
        "@saji/brace-rules/brace-on-same-line": [
            "error",
            "stroustrup",
            {
                "ClassDeclaration": "never",
                "ExportClass": "never",
                "ExportClassAnon": "never",
                "ExportFunctionAnon": "never"
            }
        ],
        ...
    }
}

Supported Rules

The basic schema for the brance-on-same-line is as follows:

"@saji/brace-rules/brace-on-same-line": [
    ${standard eslint error levels, int/string-based},
(( schema ))
    {
        oneOf: [
            { enum: ["1tbs", "stroustrup", "allman"] },
            {
                type: "object",
                properties: { ...braceRuleProps }
            }
        ]
    },
    {
        type: "object",
        properties:
            ...braceRuleProps,
            allowSingleLine: { type: "boolean" },
            noCuddledElse: { type: "boolean" },
            noCuddledCatchFinally: { type: "boolean" }
        }),
        additionalProperties: false
    }
(( end schema ))
]

The anticipated flow here is to start with a base brace-style ruleset (i.e. stroustrup), and override it with specific rules (as shown in the example from the Usage section, above).

You can also completely define your brace-style rules on a per-keyword basis by specifying them all in the section following the error level. No additional braceStyle properties would need to be added in the third section, which overrides anything specified in the second section.

Properties that can be defined in the third section:

  • ...braceRuleProps: See below in braceRuleProps for full details
  • allowSingleLine: Allow braces on single-line declarations
    if (foo) { return true; }
  • noCuddledElse: Don't allow the else keyword to be on the same line as the closing brace of the preceeding if clause.
  • noCuddledCatchFinally: Don't allow catch or finally keywords to be on the same line as the closing brace of the preceeding try and catch clauses (respectively).

braceRuleProps

Below is the list of all brace rules that can be used. They all accept one of three values:

  • always: Always require an opening brace on the same line as the keyword
  • never: Never allow an opening brace on the same line as the keyword
  • ignore: Ignore the bracing style for this keyword

Most of the brace rules are self-explanatary:

"The WithStatement rule is for formatting braces around with statements"

... but a few related to export need additional detail:

  • ArrowFunctionExpression
  • ClassDeclaration
  • DoWhileStatement
  • ExportClass: Adjusts brace formatting for export class MyClass or export default class MyClass declarations (overriding any ClassDeclaration setting)
  • ExportClassAnon: Adjusts brace formatting for export default class declarations (overriding any ClassDeclaration and ExportClass settings)
  • ExportFunction: Adjusts brace formatting for export function MyFunction or export default function MyFunction declarations (overriding any FunctionDeclaration setting)
  • ExportFunctionAnon: Adjusts brace formatting for export default function declarations (overriding any FunctionDeclaration and ExportFunction settings)
  • ForInStatement
  • ForOfStatement
  • ForStatement
  • FunctionDeclaration
  • FunctionExpression
  • IfStatement
  • MethodDeclaration: Adjusts brace formatting for class method declaration
  • SwitchStatement
  • TryStatement
  • WhileStatement
  • WithStatement