-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support flat config and eslint v9 (#1073)
* feat: support flat config * refactor: tweak test context * fix: update docs & tweak vitepress * fix: remove * fix: add name for eslint inspector debugging * test: eslint v9 testing * fix: support eslint v8.x and v9 compatibility * 🙈 Add .eslintignore file to skip test fixtures * 🚚 Move fixtures to a separate __fixtures__ folder * 🚨 Fix prettier warnings * 🐛 Prettier broke @ts-expect-error --------- Co-authored-by: Vinícius Hoyer <[email protected]>
- Loading branch information
Showing
28 changed files
with
373 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__fixtures__/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/.husky/ | ||
/.idea/ | ||
/dist/ | ||
/node_modules/ | ||
node_modules | ||
/docs/.vitepress/dist | ||
/docs/.vitepress/cache | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
.eslintcache | ||
.eslintignore | ||
.gitignore | ||
.husky | ||
.npmignore | ||
.prettierignore | ||
LICENSE | ||
yarn.lock | ||
dist | ||
__fixtures__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<div> | ||
<img src="foo" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { ref } from "vue"; | ||
const counter = ref(0); | ||
console.log("counter", counter); | ||
</script> |
10 changes: 10 additions & 0 deletions
10
__tests__/integrations/__fixtures__/flat-config/eslint.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import plugin from "eslint-plugin-vuejs-accessibility"; | ||
|
||
export default [ | ||
...plugin.configs["flat/recommended"], | ||
{ | ||
rules: { | ||
"vuejs-accessibility/alt-text": "warn" | ||
} | ||
} | ||
]; |
11 changes: 11 additions & 0 deletions
11
__tests__/integrations/__fixtures__/flat-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"private": true, | ||
"name": "integration-test-for-flat-config", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "Integration test for flat config", | ||
"dependencies": { | ||
"eslint": "^9.0.0", | ||
"eslint-plugin-vuejs-accessibility": "file:../../../.." | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
__tests__/integrations/__fixtures__/legacy-config/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"root": true, | ||
"extends": ["plugin:vuejs-accessibility/recommended"], | ||
"plugins": ["vuejs-accessibility"], | ||
"parser": "vue-eslint-parser", | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion": 2019 | ||
}, | ||
"rules": { | ||
"vuejs-accessibility/alt-text": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<div> | ||
<img src="foo" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { ref } from "vue"; | ||
const counter = ref(0); | ||
console.log("counter", counter); | ||
</script> |
11 changes: 11 additions & 0 deletions
11
__tests__/integrations/__fixtures__/legacy-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"private": true, | ||
"name": "integration-test-for-legacy-config", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "Integration test for legacy config", | ||
"dependencies": { | ||
"eslint": "^8.57.0-0", | ||
"eslint-plugin-vuejs-accessibility": "file:../../../.." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import cp from "child_process"; | ||
import path from "path"; | ||
import semver from "semver"; | ||
import { readPackageJson } from "./helper"; | ||
|
||
const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`; | ||
|
||
describe("Integration with flat config", () => { | ||
let originalCwd: null | string = null; | ||
const dirFixture = path.join(__dirname, "__fixtures__/flat-config"); | ||
|
||
beforeEach(() => { | ||
originalCwd = process.cwd(); | ||
process.chdir(dirFixture); | ||
cp.execSync("npm i -f", { stdio: "inherit" }); | ||
}); | ||
afterEach(() => { | ||
originalCwd && process.chdir(originalCwd); | ||
}); | ||
|
||
it("should work with config", () => { | ||
expect.assertions(2); | ||
|
||
const eslintPackageJson = readPackageJson( | ||
path.resolve(dirFixture, "node_modules/eslint") | ||
); | ||
|
||
if (!semver.satisfies(process.version, eslintPackageJson.engines.node)) { | ||
return; | ||
} | ||
|
||
const result = JSON.parse( | ||
cp.execSync(`${ESLINT} a.vue --max-warnings 1 --format=json`, { | ||
encoding: "utf-8" | ||
}) | ||
); | ||
expect(result.length).toBe(1); | ||
expect(result[0].messages[0].messageId).toBe("imgMissingAlt"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export function readPackageJson(base: string) { | ||
return JSON.parse( | ||
fs.readFileSync(path.resolve(base, "package.json"), "utf-8") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import cp from "child_process"; | ||
import path from "path"; | ||
import semver from "semver"; | ||
import { readPackageJson } from "./helper"; | ||
|
||
const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`; | ||
|
||
describe("Integration with legacy config", () => { | ||
let originalCwd: null | string = null; | ||
const dirFixture = path.join(__dirname, "__fixtures__/legacy-config"); | ||
|
||
beforeEach(() => { | ||
originalCwd = process.cwd(); | ||
process.chdir(dirFixture); | ||
cp.execSync("npm i -f", { stdio: "inherit" }); | ||
}); | ||
afterEach(() => { | ||
originalCwd && process.chdir(originalCwd); | ||
}); | ||
|
||
it("should work with config", () => { | ||
expect.assertions(2); | ||
|
||
const eslintPackageJson = readPackageJson( | ||
path.resolve(dirFixture, "node_modules/eslint") | ||
); | ||
|
||
if (!semver.satisfies(process.version, eslintPackageJson.engines.node)) { | ||
return; | ||
} | ||
|
||
const result = JSON.parse( | ||
cp.execSync(`${ESLINT} a.vue --max-warnings 1 --format=json`, { | ||
encoding: "utf-8" | ||
}) | ||
); | ||
expect(result.length).toBe(1); | ||
expect(result[0].messages[0].messageId).toBe("imgMissingAlt"); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import globals from "globals"; | ||
import { rules } from "../rules"; | ||
|
||
const recommended = [ | ||
{ | ||
name: "vuejs-accessibility:setup:base", | ||
plugins: { | ||
get "vuejs-accessibility"() { | ||
return require("../../index"); | ||
} | ||
}, | ||
languageOptions: { | ||
sourceType: "module", | ||
globals: globals.browser | ||
} | ||
}, | ||
{ | ||
name: "vuejs-accessibility:setup:with-files-rules-and-parser", | ||
files: ["*.vue", "**/*.vue"], | ||
plugins: { | ||
get "vuejs-accessibility"() { | ||
return require("../../index"); | ||
} | ||
}, | ||
languageOptions: { | ||
parser: require("vue-eslint-parser"), | ||
sourceType: "module", | ||
globals: globals.browser | ||
}, | ||
rules | ||
} | ||
]; | ||
|
||
export = recommended; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Linter } from "eslint"; | ||
|
||
const rules = { | ||
"vuejs-accessibility/alt-text": "error", | ||
"vuejs-accessibility/anchor-has-content": "error", | ||
"vuejs-accessibility/aria-props": "error", | ||
"vuejs-accessibility/aria-role": "error", | ||
"vuejs-accessibility/aria-unsupported-elements": "error", | ||
"vuejs-accessibility/click-events-have-key-events": "error", | ||
"vuejs-accessibility/form-control-has-label": "error", | ||
"vuejs-accessibility/heading-has-content": "error", | ||
"vuejs-accessibility/iframe-has-title": "error", | ||
"vuejs-accessibility/interactive-supports-focus": "error", | ||
"vuejs-accessibility/label-has-for": "error", | ||
"vuejs-accessibility/media-has-caption": "error", | ||
"vuejs-accessibility/mouse-events-have-key-events": "error", | ||
"vuejs-accessibility/no-access-key": "error", | ||
"vuejs-accessibility/no-autofocus": "error", | ||
"vuejs-accessibility/no-distracting-elements": "error", | ||
"vuejs-accessibility/no-redundant-roles": "error", | ||
"vuejs-accessibility/no-static-element-interactions": "error", | ||
"vuejs-accessibility/role-has-required-aria-props": "error", | ||
"vuejs-accessibility/tabindex-no-positive": "error" | ||
} satisfies Linter.RulesRecord; | ||
|
||
export { rules }; |
Oops, something went wrong.