Skip to content

Commit

Permalink
Configure @stylistic/brace-style rule (#14)
Browse files Browse the repository at this point in the history
Despite what [the docs](https://eslint.style/rules/default/brace-style)
say, `1tbs` is not the default configuration for this rule. `1tbs` is
our preferred style, so this change configures the rule thusly.

Good style:

```js
if (some_condition == other_condition) {
  console.log("hooray!");
} else if (some_condition == some_other_condition) {
  console.log("also hooray!");
} else {
  console.log("boo!");
}
```
  • Loading branch information
jgarber623-cargosense authored Jul 23, 2024
2 parents a8cca5b + 8aa4fdd commit db26aa5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export default [
*/
"@stylistic/array-element-newline": ["error", "consistent"],

/**
* Enforce consistent brace style for blocks.
*
* @see {@link https://eslint.style/rules/default/brace-style}
*/
"@stylistic/brace-style": ["error", "1tbs"],

/**
* Enforce consistent usage of line breaks between arguments of a function
* call.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" :"@cargosense/eslint-config",
"version": "1.1.0",
"version": "1.2.0",
"description": "Shareable ESLint configuration.",
"keywords": [
"eslint-config",
Expand Down
26 changes: 25 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ test("loads config and invalidates incorrect syntax", async () => {
});

const expected = [
{
column: 8,
endColumn: 9,
endLine: 1,
fix: { range: [8, 8], text: "\n" },
line: 1,
message: "Statement inside of curly braces should be on next line.",
messageId: "blockSameLine",
nodeType: "Punctuator",
ruleId: "@stylistic/brace-style",
severity: 2,
},
{
column: 10,
endColumn: 26,
Expand All @@ -51,6 +63,18 @@ test("loads config and invalidates incorrect syntax", async () => {
ruleId: "array-func/prefer-flat-map",
severity: 2,
},
{
column: 27,
endColumn: 28,
endLine: 1,
fix: { range: [26, 26], text: "\n" },
line: 1,
message: "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.",
messageId: "singleLineClose",
nodeType: "Punctuator",
ruleId: "@stylistic/brace-style",
severity: 2,
},
{
column: 28,
fix: { range: [28, 29], text: "" },
Expand All @@ -75,6 +99,6 @@ test("loads config and invalidates incorrect syntax", async () => {
},
];

assert.strictEqual(errorCount, 4);
assert.strictEqual(errorCount, 6);
assert.deepEqual(messages, expected);
});

0 comments on commit db26aa5

Please sign in to comment.