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

brace-style: else if on same line #255

Closed
3 of 4 tasks
Splines opened this issue Jan 3, 2024 · 3 comments
Closed
3 of 4 tasks

brace-style: else if on same line #255

Splines opened this issue Jan 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Splines
Copy link

Splines commented Jan 3, 2024

Clear and concise description of the problem

Currently the brace-style does not allow for an option where else if, else etc. are placed next to the closing }. E.g. I'd love to use 1tbs as style with the following example being correct:

function dummyFunc() {
  const a = "dummy";
  if (a) {
    console.log("test true");
  } else if (a === "dummy") {
    console.log("dummy");
  } else {
    console.log("else");
  }
}

Suggested solution

No suggested solution yet. This issue might be relevant.

Alternative

No response

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
@MetRonnie
Copy link

MetRonnie commented Apr 9, 2024

This seems like a bug to me

Edit: when using the shared config it works correctly when you explicitly specify 1tbs

module.exports = [
    stylistic.configs.customize({
        braceStyle: '1tbs',
    }),

however leaving it to the default which is supposed to be 1tbs seems to be bugged

Edit edit: see #184 (comment), migrating from ESLint v8 this is all rather confusing...

@Splines
Copy link
Author

Splines commented Apr 9, 2024

Ahh, I found the error. I specified brace-style instead of braceStyle as key for the rule, so it was not even considered at all 🙈 Now it works just fine and 1tbs is the style I wanted. I assumed the key was called brace-style since this is the title of the respective docs page. But one has to look into the source code in order to find the real name (or I've overlooked it in the documentation):

/**
* Which brace style to use
* @default 'stroustrup'
*/
braceStyle?: '1tbs' | 'stroustrup' | 'allman'

@Splines Splines closed this as completed Apr 9, 2024
@Splines
Copy link
Author

Splines commented Apr 9, 2024

@MetRonnie

however leaving it to the default which is supposed to be 1tbs seems to be bugged

With regards to the defaults, see #163 for this, this is not actually a bug but wanted behavior (yes, it might be confusing, but that's up to the maintainers of this project to decide). The configuration factory method is working fine for me and you have fine-grained control over the rules you want to use.

// my eslint.config.mjs file
import js from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import erb from "eslint-plugin-erb";
import globals from "globals";

export default [
  js.configs.recommended,
  // Allow linting of ERB files, see https://github.com/Splines/eslint-plugin-erb
  erb.configs.recommended,
  // Globally ignore the following paths
  {
    ignores: [
      "node_modules/"
    ],
  },
  {
    plugins: {
      "@stylistic": stylistic,
    },
    rules: {
      ...stylistic.configs.customize({
        "indent": 2,
        "jsx": false,
        "quoteProps": "always",
        "semi": "always",
        "braceStyle": "1tbs",
      }).rules,
      "@stylistic/quotes": ["error", "double", { avoidEscape: true }],
      "no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
    },
    languageOptions: {
      ecmaVersion: 2022,
      sourceType: "module",
      globals: {
        ...customGlobals,
        ...globals.browser,
        ...globals.jquery,
        ...globals.node,
      },
    },
    linterOptions: {
      // see https://github.com/Splines/eslint-plugin-erb/releases/tag/v2.0.1
      reportUnusedDisableDirectives: "off",
    },
  },
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants