Skip to content

Commit c4651b1

Browse files
authored
Merge pull request #1 from Kenneth-Sills/kesills-fix-tests
Update Unit Tests for `@stylistic` Plugins
2 parents 278db1d + 1977134 commit c4651b1

File tree

8 files changed

+71
-8
lines changed

8 files changed

+71
-8
lines changed

.changeset/purple-snakes-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-config-prettier": minor
3+
---
4+
5+
add support for @stylistic formatting rules

.eslintrc.base.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,25 @@ module.exports = {
9595
},
9696
},
9797
{
98-
files: ["test-lint/{react,flowtype}.js"],
98+
files: ["test-lint/{react,flowtype}.js", "test-lint/@stylistic__jsx.jsx"],
9999
parserOptions: { parser: "@babel/eslint-parser" },
100100
},
101+
{
102+
files: ["test-lint/@stylistic.js"],
103+
extends: ["plugin:@stylistic/all-extends"],
104+
},
105+
{
106+
files: ["test-lint/@stylistic__js.js"],
107+
extends: ["plugin:@stylistic/js/all-extends"],
108+
},
109+
{
110+
files: ["test-lint/@stylistic__jsx.jsx"],
111+
extends: ["plugin:@stylistic/jsx/all-extends"],
112+
},
113+
{
114+
files: ["test-lint/@stylistic__ts.ts"],
115+
extends: ["plugin:@stylistic/ts/all-extends"],
116+
},
101117
],
102118
settings: {
103119
react: {

eslint.base.config.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,23 @@ module.exports = [
8989
...vue.configs.recommended.rules,
9090
},
9191
},
92-
...eslintrcBase.overrides.map(({ parserOptions, ...override }) => ({
93-
...override,
94-
languageOptions: { parser: require(parserOptions.parser) },
95-
})),
92+
...eslintrcBase.overrides
93+
.filter(({ parserOptions }) => parserOptions)
94+
.map(({ parserOptions, ...override }) => ({
95+
...override,
96+
languageOptions: { parser: require(parserOptions.parser) },
97+
})),
9698
{ files: ["test-lint/@stylistic.js"], ...stylistic.configs["all-flat"] },
99+
{
100+
files: ["test-lint/@stylistic__js.js"],
101+
...stylisticJs.configs["all-flat"],
102+
},
103+
{
104+
files: ["test-lint/@stylistic__jsx.jsx"],
105+
...stylisticJsx.configs["all-flat"],
106+
},
107+
{
108+
files: ["test-lint/@stylistic__ts.ts"],
109+
...stylisticTs.configs["all-flat"],
110+
},
97111
];

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"prettier": "prettier --write .",
2121
"test:prettier": "prettier --check .",
2222
"test:eslint": "eslint .",
23-
"test:lint-verify-fail": "eslint \"test-lint/*.{js,ts,vue}\" --config .eslintrc.base.js --format json",
24-
"test:lint-verify-fail:flat": "eslint \"test-lint/*.{js,ts,vue}\" --config eslint.base.config.js --format json",
23+
"test:lint-verify-fail": "eslint \"test-lint/*.{js,jsx,ts,vue}\" --config .eslintrc.base.js --format json",
24+
"test:lint-verify-fail:flat": "eslint \"test-lint/*.{js,jsx,ts,vue}\" --config eslint.base.config.js --format json",
2525
"test:lint-rules": "eslint index.js --config test-config/.eslintrc.js --format json",
2626
"test:lint-rules:flat": "eslint index.js --config test-config/eslint.config.js --format json",
2727
"test:deprecated": "eslint-find-rules --deprecated index.js",

test-lint/@stylistic__js.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable quotes,max-len,curly */
2+
"use strict";
3+
4+
// Prettier wants a newline after the condition, but `eslint-config-google` does not.
5+
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
6+
updateCart(cart);

test-lint/@stylistic__jsx.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable quotes, react/jsx-max-props-per-line */
2+
"use strict";
3+
4+
const React = require("react");
5+
6+
// Prettier wants several attributes on the same line, but "plugin:react/all"
7+
// only allows one per line.
8+
module.exports = <div className id />;

test-lint/@stylistic__ts.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable quotes,max-len,curly,@typescript-eslint/indent */
2+
"use strict";
3+
4+
// Prettier wants a newline after the condition, but `eslint-config-google` does not.
5+
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
6+
updateCart(cart);

test/lint-verify-fail.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("test-lint/ causes errors without eslint-config-prettier", () => {
5252
output.forEach((data) => {
5353
const name = path
5454
.basename(data.filePath)
55-
.replace(/\.(?:js|ts)$|-file\.vue$/, "");
55+
.replace(/\.(?:js|jsx|ts)$|-file\.vue$/, "");
5656
const ruleIds = data.messages.map((message) => message.ruleId);
5757

5858
describe(name, () => {
@@ -70,6 +70,14 @@ describe("test-lint/ causes errors without eslint-config-prettier", () => {
7070
.filter((ruleId) => ruleId.includes("/"))
7171
.concat("no ruleId should not contain a slash")
7272
).toEqual(["no ruleId should not contain a slash"]);
73+
} else if (name.startsWith("@stylistic__")) {
74+
const stylisticGroup = name.split("__")[1];
75+
const rulePrefix = `@stylistic/${stylisticGroup}/`;
76+
expect(
77+
ruleIds
78+
.filter((ruleId) => !ruleId.startsWith(rulePrefix))
79+
.concat(`every ruleId should start with: ${rulePrefix}`)
80+
).toEqual([`every ruleId should start with: ${rulePrefix}`]);
7381
} else {
7482
expect(
7583
ruleIds

0 commit comments

Comments
 (0)