Skip to content

Commit 7cc2d17

Browse files
committed
Convert lint script over to TypeScript
1 parent cecbc2a commit 7cc2d17

File tree

8 files changed

+172
-85
lines changed

8 files changed

+172
-85
lines changed

bin/lint

-15
This file was deleted.

bin/lint.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!./node_modules/.bin/ts-node
2+
3+
import { ESLint } from "eslint";
4+
import a11yPlugin from "../src";
5+
6+
(async function main() {
7+
const eslint = new ESLint({
8+
baseConfig: a11yPlugin.configs.recommended,
9+
plugins: { "eslint-plugin-vuejs-accessibility": a11yPlugin },
10+
useEslintrc: false
11+
});
12+
13+
const results = await eslint.lintFiles(process.argv.slice(2));
14+
const formatter = await eslint.loadFormatter("stylish");
15+
16+
const resultText = formatter.format(results);
17+
console.log(resultText);
18+
})().catch((error) => {
19+
process.exitCode = 1;
20+
console.error(error);
21+
});

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/eslint-scope": "^3.7.0",
3737
"@types/eslint-visitor-keys": "^1.0.0",
3838
"@types/jest": "^26.0.23",
39+
"@types/node": "^15.6.2",
3940
"@typescript-eslint/eslint-plugin": "^4.26.0",
4041
"@typescript-eslint/parser": "^4.26.0",
4142
"eslint": "^7.3.1",
@@ -45,6 +46,7 @@
4546
"prettier": "^2.1.1",
4647
"pretty-quick": "^3.0.0",
4748
"ts-jest": "^27.0.1",
49+
"ts-node": "^10.0.0",
4850
"typescript": "^4.2.4"
4951
},
5052
"eslintConfig": {

src/index.ts

+72-65
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,83 @@
1+
import accessibleEmoji from "./rules/accessible-emoji";
2+
import altText from "./rules/alt-text";
3+
import anchorHasContent from "./rules/anchor-has-content";
4+
import ariaProps from "./rules/aria-props";
5+
import ariaRole from "./rules/aria-role";
6+
import ariaUnsupportedElements from "./rules/aria-unsupported-elements";
7+
import clickEventsHaveKeyEvents from "./rules/click-events-have-key-events";
8+
import formControlHasLabel from "./rules/form-control-has-label";
9+
import headingHasContent from "./rules/heading-has-content";
10+
import iframeHasTitle from "./rules/iframe-has-title";
11+
import interactiveSupportsFocus from "./rules/interactive-supports-focus";
12+
import labelHasFor from "./rules/label-has-for";
13+
import mediaHasCaption from "./rules/media-has-caption";
14+
import mouseEventsHaveKeyEvents from "./rules/mouse-events-have-key-events";
15+
import noAccessKey from "./rules/no-access-key";
16+
import noAutofocus from "./rules/no-autofocus";
17+
import noDistractingElements from "./rules/no-distracting-elements";
18+
import noOnchange from "./rules/no-onchange";
19+
import noRedundantRoles from "./rules/no-redundant-roles";
20+
import roleHasRequiredAriaProps from "./rules/role-has-required-aria-props";
21+
import tabindexNoPositive from "./rules/tabindex-no-positive";
22+
123
export default {
224
rules: {
3-
"accessible-emoji": require("./rules/accessible-emoji"),
4-
"alt-text": require("./rules/alt-text"),
5-
"anchor-has-content": require("./rules/anchor-has-content"),
6-
"aria-props": require("./rules/aria-props"),
7-
"aria-role": require("./rules/aria-role"),
8-
"aria-unsupported-elements": require("./rules/aria-unsupported-elements"),
9-
"click-events-have-key-events": require("./rules/click-events-have-key-events"),
10-
"form-control-has-label": require("./rules/form-control-has-label"),
11-
"heading-has-content": require("./rules/heading-has-content"),
12-
"iframe-has-title": require("./rules/iframe-has-title"),
13-
"interactive-supports-focus": require("./rules/interactive-supports-focus"),
14-
"label-has-for": require("./rules/label-has-for"),
15-
"media-has-caption": require("./rules/media-has-caption"),
16-
"mouse-events-have-key-events": require("./rules/mouse-events-have-key-events"),
17-
"no-access-key": require("./rules/no-access-key"),
18-
"no-autofocus": require("./rules/no-autofocus"),
19-
"no-distracting-elements": require("./rules/no-distracting-elements"),
20-
"no-onchange": require("./rules/no-onchange"),
21-
"no-redundant-roles": require("./rules/no-redundant-roles"),
22-
"role-has-required-aria-props": require("./rules/role-has-required-aria-props"),
23-
"tabindex-no-positive": require("./rules/tabindex-no-positive")
25+
"accessible-emoji": accessibleEmoji,
26+
"alt-text": altText,
27+
"anchor-has-content": anchorHasContent,
28+
"aria-props": ariaProps,
29+
"aria-role": ariaRole,
30+
"aria-unsupported-elements": ariaUnsupportedElements,
31+
"click-events-have-key-events": clickEventsHaveKeyEvents,
32+
"form-control-has-label": formControlHasLabel,
33+
"heading-has-content": headingHasContent,
34+
"iframe-has-title": iframeHasTitle,
35+
"interactive-supports-focus": interactiveSupportsFocus,
36+
"label-has-for": labelHasFor,
37+
"media-has-caption": mediaHasCaption,
38+
"mouse-events-have-key-events": mouseEventsHaveKeyEvents,
39+
"no-access-key": noAccessKey,
40+
"no-autofocus": noAutofocus,
41+
"no-distracting-elements": noDistractingElements,
42+
"no-onchange": noOnchange,
43+
"no-redundant-roles": noRedundantRoles,
44+
"role-has-required-aria-props": roleHasRequiredAriaProps,
45+
"tabindex-no-positive": tabindexNoPositive
2446
},
2547
configs: {
2648
recommended: {
2749
parser: require.resolve("vue-eslint-parser"),
50+
parserOptions: {
51+
ecmaVersion: 2020 as const,
52+
sourceType: "module" as const
53+
},
54+
env: {
55+
browser: true,
56+
es6: true
57+
},
2858
plugins: ["vuejs-accessibility"],
2959
rules: {
30-
"vuejs-accessibility/accessible-emoji": "error",
31-
"vuejs-accessibility/alt-text": "error",
32-
"vuejs-accessibility/anchor-has-content": "error",
33-
"vuejs-accessibility/aria-props": "error",
34-
"vuejs-accessibility/aria-role": [
35-
"error",
36-
{
37-
ignoreNonDOM: true
38-
}
39-
],
40-
"vuejs-accessibility/aria-unsupported-elements": "error",
41-
"vuejs-accessibility/click-events-have-key-events": "error",
42-
"vuejs-accessibility/form-control-has-label": "error",
43-
"vuejs-accessibility/heading-has-content": "error",
44-
"vuejs-accessibility/iframe-has-title": "error",
45-
"vuejs-accessibility/interactive-supports-focus": [
46-
"error",
47-
{
48-
tabbable: [
49-
"button",
50-
"checkbox",
51-
"link",
52-
"searchbox",
53-
"spinbutton",
54-
"switch",
55-
"textbox"
56-
]
57-
}
58-
],
59-
"vuejs-accessibility/label-has-for": "error",
60-
"vuejs-accessibility/media-has-caption": "error",
61-
"vuejs-accessibility/mouse-events-have-key-events": "error",
62-
"vuejs-accessibility/no-access-key": "error",
63-
"vuejs-accessibility/no-autofocus": [
64-
"error",
65-
{
66-
ignoreNonDOM: true
67-
}
68-
],
69-
"vuejs-accessibility/no-distracting-elements": "error",
70-
"vuejs-accessibility/no-onchange": "error",
71-
"vuejs-accessibility/no-redundant-roles": "error",
72-
"vuejs-accessibility/role-has-required-aria-props": "error",
73-
"vuejs-accessibility/tabindex-no-positive": "error"
60+
"vuejs-accessibility/accessible-emoji": "error" as const,
61+
"vuejs-accessibility/alt-text": "error" as const,
62+
"vuejs-accessibility/anchor-has-content": "error" as const,
63+
"vuejs-accessibility/aria-props": "error" as const,
64+
"vuejs-accessibility/aria-role": "error" as const,
65+
"vuejs-accessibility/aria-unsupported-elements": "error" as const,
66+
"vuejs-accessibility/click-events-have-key-events": "error" as const,
67+
"vuejs-accessibility/form-control-has-label": "error" as const,
68+
"vuejs-accessibility/heading-has-content": "error" as const,
69+
"vuejs-accessibility/iframe-has-title": "error" as const,
70+
"vuejs-accessibility/interactive-supports-focus": "error" as const,
71+
"vuejs-accessibility/label-has-for": "error" as const,
72+
"vuejs-accessibility/media-has-caption": "error" as const,
73+
"vuejs-accessibility/mouse-events-have-key-events": "error" as const,
74+
"vuejs-accessibility/no-access-key": "error" as const,
75+
"vuejs-accessibility/no-autofocus": "error" as const,
76+
"vuejs-accessibility/no-distracting-elements": "error" as const,
77+
"vuejs-accessibility/no-onchange": "error" as const,
78+
"vuejs-accessibility/no-redundant-roles": "error" as const,
79+
"vuejs-accessibility/role-has-required-aria-props": "error" as const,
80+
"vuejs-accessibility/tabindex-no-positive": "error" as const
7481
}
7582
}
7683
}

src/rules/aria-role.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const rule: Rule.RuleModule = {
2828
type: "object",
2929
properties: {
3030
ignoreNonDOM: {
31-
type: "boolean"
31+
type: "boolean",
32+
default: true
3233
}
3334
},
3435
additionalProperties: false

src/rules/interactive-supports-focus.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ const rule: InteractiveSupportsFocus = {
117117
type: "array",
118118
items: {
119119
type: "string",
120-
enum: interactiveRoles
120+
enum: interactiveRoles,
121+
default: [
122+
"button",
123+
"checkbox",
124+
"link",
125+
"searchbox",
126+
"spinbutton",
127+
"switch",
128+
"textbox"
129+
]
121130
},
122131
uniqueItems: true,
123132
additionalItems: false

src/rules/no-autofocus.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const rule: Rule.RuleModule = {
2222
type: "object",
2323
properties: {
2424
ignoreNonDOM: {
25-
type: "boolean"
25+
type: "boolean",
26+
default: true
2627
}
2728
},
2829
additionalProperties: false

yarn.lock

+63-2
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,26 @@
567567
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
568568
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
569569

570+
"@tsconfig/node10@^1.0.7":
571+
version "1.0.7"
572+
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.7.tgz#1eb1de36c73478a2479cc661ef5af1c16d86d606"
573+
integrity sha512-aBvUmXLQbayM4w3A8TrjwrXs4DZ8iduJnuJLLRGdkWlyakCf1q6uHZJBzXoRA/huAEknG5tcUyQxN3A+In5euQ==
574+
575+
"@tsconfig/node12@^1.0.7":
576+
version "1.0.7"
577+
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.7.tgz#677bd9117e8164dc319987dd6ff5fc1ba6fbf18b"
578+
integrity sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A==
579+
580+
"@tsconfig/node14@^1.0.0":
581+
version "1.0.0"
582+
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.0.tgz#5bd046e508b1ee90bc091766758838741fdefd6e"
583+
integrity sha512-RKkL8eTdPv6t5EHgFKIVQgsDapugbuOptNd9OOunN/HAkzmmTnZELx1kNCK0rSdUYGmiFMM3rRQMAWiyp023LQ==
584+
585+
"@tsconfig/node16@^1.0.1":
586+
version "1.0.1"
587+
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
588+
integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==
589+
570590
"@types/aria-query@^4.2.1":
571591
version "4.2.1"
572592
resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-4.2.1.tgz#78b5433344e2f92e8b306c06a5622c50c245bf6b"
@@ -680,6 +700,11 @@
680700
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08"
681701
integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==
682702

703+
"@types/node@^15.6.2":
704+
version "15.6.2"
705+
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.2.tgz#c61d49f38af70da32424b5322eee21f97e627175"
706+
integrity sha512-dxcOx8801kMo3KlU+C+/ctWrzREAH7YvoF3aoVpRdqgs+Kf7flp+PJDN/EX5bME3suDUZHsxes9hpvBmzYlWbA==
707+
683708
"@types/prettier@^2.1.5":
684709
version "2.2.3"
685710
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.2.3.tgz#ef65165aea2924c9359205bf748865b8881753c0"
@@ -883,6 +908,11 @@ anymatch@^3.0.3:
883908
normalize-path "^3.0.0"
884909
picomatch "^2.0.4"
885910

911+
arg@^4.1.0:
912+
version "4.1.3"
913+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
914+
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
915+
886916
argparse@^1.0.7:
887917
version "1.0.10"
888918
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -1171,6 +1201,11 @@ core-js-pure@^3.0.0:
11711201
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.13.1.tgz#5d139d346780f015f67225f45ee2362a6bed6ba1"
11721202
integrity sha512-wVlh0IAi2t1iOEh16y4u1TRk6ubd4KvLE8dlMi+3QUI6SfKphQUh7tAwihGGSQ8affxEXpVIPpOdf9kjR4v4Pw==
11731203

1204+
create-require@^1.1.0:
1205+
version "1.1.1"
1206+
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
1207+
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
1208+
11741209
cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
11751210
version "7.0.3"
11761211
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@@ -1253,6 +1288,11 @@ diff-sequences@^27.0.1:
12531288
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.1.tgz#9c9801d52ed5f576ff0a20e3022a13ee6e297e7c"
12541289
integrity sha512-XPLijkfJUh/PIBnfkcSHgvD6tlYixmcMAn3osTk6jt+H0v/mgURto1XUiD9DKuGX5NDoVS6dSlA23gd9FUaCFg==
12551290

1291+
diff@^4.0.1:
1292+
version "4.0.2"
1293+
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
1294+
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
1295+
12561296
dir-glob@^3.0.1:
12571297
version "3.0.1"
12581298
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@@ -2486,7 +2526,7 @@ make-dir@^3.0.0:
24862526
dependencies:
24872527
semver "^6.0.0"
24882528

2489-
2529+
[email protected], make-error@^1.1.1:
24902530
version "1.3.6"
24912531
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
24922532
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
@@ -2943,7 +2983,7 @@ slice-ansi@^4.0.0:
29432983
astral-regex "^2.0.0"
29442984
is-fullwidth-code-point "^3.0.0"
29452985

2946-
source-map-support@^0.5.6:
2986+
source-map-support@^0.5.17, source-map-support@^0.5.6:
29472987
version "0.5.19"
29482988
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
29492989
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
@@ -3139,6 +3179,22 @@ ts-jest@^27.0.1:
31393179
semver "7.x"
31403180
yargs-parser "20.x"
31413181

3182+
ts-node@^10.0.0:
3183+
version "10.0.0"
3184+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
3185+
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
3186+
dependencies:
3187+
"@tsconfig/node10" "^1.0.7"
3188+
"@tsconfig/node12" "^1.0.7"
3189+
"@tsconfig/node14" "^1.0.0"
3190+
"@tsconfig/node16" "^1.0.1"
3191+
arg "^4.1.0"
3192+
create-require "^1.1.0"
3193+
diff "^4.0.1"
3194+
make-error "^1.1.1"
3195+
source-map-support "^0.5.17"
3196+
yn "3.1.1"
3197+
31423198
tslib@^1.8.1:
31433199
version "1.14.1"
31443200
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
@@ -3365,3 +3421,8 @@ yargs@^16.0.3:
33653421
string-width "^4.2.0"
33663422
y18n "^5.0.5"
33673423
yargs-parser "^20.2.2"
3424+
3425+
3426+
version "3.1.1"
3427+
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
3428+
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

0 commit comments

Comments
 (0)