-
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: support flat config and eslint v9 #1073
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
Changes from 3 commits
932aba2
07b9b56
205370a
3125a9d
1acacc8
b85b038
dacc876
4e50a16
57eddcc
05e1c47
643fe21
138b36b
ccee8ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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; | ||
|
||
beforeEach(() => { | ||
originalCwd = process.cwd(); | ||
process.chdir(path.join(__dirname, "flat-config")); | ||
cp.execSync("npm i -f", { stdio: "inherit" }); | ||
}); | ||
afterEach(() => { | ||
originalCwd && process.chdir(originalCwd); | ||
}); | ||
|
||
it("should work with config", () => { | ||
if ( | ||
!semver.satisfies( | ||
process.version, | ||
readPackageJson( | ||
path.resolve(__dirname, "flat-config/node_modules/eslint") | ||
).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"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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> |
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" | ||
} | ||
} | ||
]; |
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": "^8.57.0-0", | ||
"eslint-plugin-vuejs-accessibility": "file:../../.." | ||
} | ||
} |
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") | ||
); | ||
} |
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; | ||
|
||
beforeEach(() => { | ||
originalCwd = process.cwd(); | ||
process.chdir(path.join(__dirname, "legacy-config")); | ||
cp.execSync("npm i -f", { stdio: "inherit" }); | ||
}); | ||
afterEach(() => { | ||
originalCwd && process.chdir(originalCwd); | ||
}); | ||
|
||
it("should work with config", () => { | ||
if ( | ||
!semver.satisfies( | ||
process.version, | ||
readPackageJson( | ||
path.resolve(__dirname, "legacy-config/node_modules/eslint") | ||
).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"); | ||
}); | ||
}); |
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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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> |
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:../../.." | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ td:last-of-type { | |
width: 50px; | ||
} | ||
</style> | ||
./rule-overview.data.mjs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { defineLoader } from "vitepress"; | ||
import recommended from "../../src/configs/recommended"; | ||
import { rules } from "../.vitepress/rulesForSidebar"; | ||
import { rules as baseRules } from "../../src/configs/base.js"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vitepress support only esm, so |
||
import { rules } from "../.vitepress/rulesForSidebar.js"; | ||
|
||
export type Data = Array<{ | ||
name: string; | ||
|
@@ -23,8 +23,8 @@ export default defineLoader({ | |
}); | ||
|
||
function getRecommendedRules() { | ||
if (recommended.rules) { | ||
return Object.keys(recommended.rules).map(removeRulePrefix); | ||
if (baseRules) { | ||
return Object.keys(baseRules).map(removeRulePrefix); | ||
} | ||
return []; | ||
} | ||
|
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 }; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've referenced eslint-plugin-vue for implementation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import globals from "globals"; | ||
import { rules } from "../base"; | ||
|
||
const recommended = [ | ||
{ | ||
plugins: { | ||
get "vuejs-accessibility"() { | ||
return require("../../index"); | ||
} | ||
}, | ||
languageOptions: { | ||
sourceType: "module", | ||
globals: globals.browser | ||
} | ||
}, | ||
{ | ||
files: ["*.vue", "**/*.vue"], | ||
plugins: { | ||
get "vuejs-accessibility"() { | ||
return require("../../index"); | ||
} | ||
}, | ||
languageOptions: { | ||
parser: require("vue-eslint-parser"), | ||
sourceType: "module", | ||
globals: globals.browser | ||
}, | ||
rules | ||
} | ||
]; | ||
|
||
export = recommended; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid vitepress (vite) trouble
https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only