Skip to content

Commit

Permalink
Merge pull request #1 from Kenneth-Sills/kesills-fix-tests
Browse files Browse the repository at this point in the history
Update Unit Tests for `@stylistic` Plugins
  • Loading branch information
abrahamguo authored Sep 30, 2024
2 parents 278db1d + 1977134 commit c4651b1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-snakes-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-config-prettier": minor
---

add support for @stylistic formatting rules
18 changes: 17 additions & 1 deletion .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,25 @@ module.exports = {
},
},
{
files: ["test-lint/{react,flowtype}.js"],
files: ["test-lint/{react,flowtype}.js", "test-lint/@stylistic__jsx.jsx"],
parserOptions: { parser: "@babel/eslint-parser" },
},
{
files: ["test-lint/@stylistic.js"],
extends: ["plugin:@stylistic/all-extends"],
},
{
files: ["test-lint/@stylistic__js.js"],
extends: ["plugin:@stylistic/js/all-extends"],
},
{
files: ["test-lint/@stylistic__jsx.jsx"],
extends: ["plugin:@stylistic/jsx/all-extends"],
},
{
files: ["test-lint/@stylistic__ts.ts"],
extends: ["plugin:@stylistic/ts/all-extends"],
},
],
settings: {
react: {
Expand Down
22 changes: 18 additions & 4 deletions eslint.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,23 @@ module.exports = [
...vue.configs.recommended.rules,
},
},
...eslintrcBase.overrides.map(({ parserOptions, ...override }) => ({
...override,
languageOptions: { parser: require(parserOptions.parser) },
})),
...eslintrcBase.overrides
.filter(({ parserOptions }) => parserOptions)
.map(({ parserOptions, ...override }) => ({
...override,
languageOptions: { parser: require(parserOptions.parser) },
})),
{ files: ["test-lint/@stylistic.js"], ...stylistic.configs["all-flat"] },
{
files: ["test-lint/@stylistic__js.js"],
...stylisticJs.configs["all-flat"],
},
{
files: ["test-lint/@stylistic__jsx.jsx"],
...stylisticJsx.configs["all-flat"],
},
{
files: ["test-lint/@stylistic__ts.ts"],
...stylisticTs.configs["all-flat"],
},
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"prettier": "prettier --write .",
"test:prettier": "prettier --check .",
"test:eslint": "eslint .",
"test:lint-verify-fail": "eslint \"test-lint/*.{js,ts,vue}\" --config .eslintrc.base.js --format json",
"test:lint-verify-fail:flat": "eslint \"test-lint/*.{js,ts,vue}\" --config eslint.base.config.js --format json",
"test:lint-verify-fail": "eslint \"test-lint/*.{js,jsx,ts,vue}\" --config .eslintrc.base.js --format json",
"test:lint-verify-fail:flat": "eslint \"test-lint/*.{js,jsx,ts,vue}\" --config eslint.base.config.js --format json",
"test:lint-rules": "eslint index.js --config test-config/.eslintrc.js --format json",
"test:lint-rules:flat": "eslint index.js --config test-config/eslint.config.js --format json",
"test:deprecated": "eslint-find-rules --deprecated index.js",
Expand Down
6 changes: 6 additions & 0 deletions test-lint/@stylistic__js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable quotes,max-len,curly */
"use strict";

// Prettier wants a newline after the condition, but `eslint-config-google` does not.
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
updateCart(cart);
8 changes: 8 additions & 0 deletions test-lint/@stylistic__jsx.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable quotes, react/jsx-max-props-per-line */
"use strict";

const React = require("react");

// Prettier wants several attributes on the same line, but "plugin:react/all"
// only allows one per line.
module.exports = <div className id />;
6 changes: 6 additions & 0 deletions test-lint/@stylistic__ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable quotes,max-len,curly,@typescript-eslint/indent */
"use strict";

// Prettier wants a newline after the condition, but `eslint-config-google` does not.
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
updateCart(cart);
10 changes: 9 additions & 1 deletion test/lint-verify-fail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("test-lint/ causes errors without eslint-config-prettier", () => {
output.forEach((data) => {
const name = path
.basename(data.filePath)
.replace(/\.(?:js|ts)$|-file\.vue$/, "");
.replace(/\.(?:js|jsx|ts)$|-file\.vue$/, "");
const ruleIds = data.messages.map((message) => message.ruleId);

describe(name, () => {
Expand All @@ -70,6 +70,14 @@ describe("test-lint/ causes errors without eslint-config-prettier", () => {
.filter((ruleId) => ruleId.includes("/"))
.concat("no ruleId should not contain a slash")
).toEqual(["no ruleId should not contain a slash"]);
} else if (name.startsWith("@stylistic__")) {
const stylisticGroup = name.split("__")[1];
const rulePrefix = `@stylistic/${stylisticGroup}/`;
expect(
ruleIds
.filter((ruleId) => !ruleId.startsWith(rulePrefix))
.concat(`every ruleId should start with: ${rulePrefix}`)
).toEqual([`every ruleId should start with: ${rulePrefix}`]);
} else {
expect(
ruleIds
Expand Down

0 comments on commit c4651b1

Please sign in to comment.