Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vue-a11y/eslint-plugin-vuejs-accessibility
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.1
Choose a base ref
...
head repository: vue-a11y/eslint-plugin-vuejs-accessibility
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.0
Choose a head ref
  • 17 commits
  • 7 files changed
  • 2 contributors

Commits on Jul 20, 2020

  1. Bump lodash from 4.17.15 to 4.17.19

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.15...4.17.19)
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored Jul 20, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e34782b View commit details
  2. Merge pull request #32 from vue-a11y/dependabot/npm_and_yarn/lodash-4…

    ….17.19
    
    Bump lodash from 4.17.15 to 4.17.19
    kddnewton authored Jul 20, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7a491b8 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2c1a63c View commit details

Commits on Jul 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    de5382c View commit details
  2. Merge pull request #33 from vue-a11y/dependabot/npm_and_yarn/jest-26.2.1

    Bump jest from 26.1.0 to 26.2.1
    kddnewton authored Jul 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    59a2996 View commit details
  3. Merge pull request #31 from vue-a11y/dependabot/npm_and_yarn/eslint-7…

    ….5.0
    
    Bump eslint from 7.4.0 to 7.5.0
    kddnewton authored Jul 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5d1f4ca View commit details

Commits on Aug 3, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    336ca1e View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4904fa8 View commit details
  3. Merge pull request #35 from vue-a11y/dependabot/npm_and_yarn/jest-26.2.2

    Bump jest from 26.2.1 to 26.2.2
    kddnewton authored Aug 3, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a53f6d2 View commit details
  4. Merge pull request #34 from vue-a11y/dependabot/npm_and_yarn/eslint-7…

    ….6.0
    
    Bump eslint from 7.5.0 to 7.6.0
    kddnewton authored Aug 3, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    850d0c6 View commit details

Commits on Aug 11, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    29e394f View commit details
  2. Merge pull request #36 from vue-a11y/dependabot/npm_and_yarn/jest-26.3.0

    Bump jest from 26.2.2 to 26.3.0
    kddnewton authored Aug 11, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    75381db View commit details

Commits on Aug 13, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    41b6b34 View commit details
  2. Merge pull request #37 from vue-a11y/dependabot/npm_and_yarn/jest-26.4.0

    Bump jest from 26.3.0 to 26.4.0
    kddnewton authored Aug 13, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    90e3538 View commit details

Commits on Aug 15, 2020

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    47ec452 View commit details
  2. Merge pull request #40 from vue-a11y/control-components

    controlComponents option for label-has-for
    kddnewton authored Aug 15, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5f84df0 View commit details
  3. Bump to v0.4.0

    kddnewton committed Aug 15, 2020

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    e8ee3ce View commit details
Showing with 462 additions and 402 deletions.
  1. +8 −1 CHANGELOG.md
  2. +5 −2 docs/label-has-for.md
  3. +1 −1 package.json
  4. +6 −2 src/rules/__tests__/label-has-for.test.js
  5. +1 −1 src/rules/__tests__/makeRuleTester.js
  6. +23 −9 src/rules/label-has-for.js
  7. +418 −386 yarn.lock
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [0.4.0] - 2020-08-15

### Added

- The `controlComponents` option for the `label-has-for` rule, which allows you to configure the rule to allow additional control components.

## [0.3.1] - 2020-07-10

### Changed
@@ -51,7 +57,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

- Initial release 🎉.

[unreleased]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.3.1...HEAD
[unreleased]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/compare/v0.1.3...v0.2.0
7 changes: 5 additions & 2 deletions docs/label-has-for.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ This rule takes one optional object argument of type object:
"vuejs-accessibility/label-has-for": [
"error",
{
"components": ["Label"],
"components": ["VLabel"],
"controlComponents": ["VInput"],
"required": {
"every": ["nesting", "id"]
},
@@ -28,7 +29,9 @@ This rule takes one optional object argument of type object:
}
```

For the `components` option, these strings determine which JSX elements (**always including** `<label>`) should be checked for having the `for` prop. This is a good use case when you have a wrapper component that simply renders a `label` element.
For the `components` option, these strings determine which elements (**always including** `<label>`) should be checked for having the `for` prop. This is a good use case when you have a wrapper component that simply renders a `label` element.

For the `controlComponents` option, these strings determine which elements should be counted as form control elements. By default, this includes `input`, `meter`, `progress`, `select`, and `textarea`. This is a good use case when you have a wrapper component that simplify renders a `input` element.

The `required` option (defaults to `"required": { "every": ["nesting", "id"] }`) determines which checks are activated. You're allowed to pass in one of the following types:

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vuejs-accessibility",
"version": "0.3.1",
"version": "0.4.0",
"description": "An eslint plugin for checking Vue.js files for accessibility",
"main": "src/index.js",
"scripts": {
8 changes: 6 additions & 2 deletions src/rules/__tests__/label-has-for.test.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@ makeRuleTester("label-has-for", rule, {
{
code: "<label for='id'><slot /></label>",
options: [{ allowChildren: true }]
},
{
code: "<label for='id'><VInput /></label>",
options: [{ controlComponents: ["VInput"] }]
}
],
invalid: [
@@ -21,8 +25,8 @@ makeRuleTester("label-has-for", rule, {
"<label for='id'><slot /></label>",
"<label for='id'><div /></label>",
{
code: "<Label for='id' />",
options: [{ components: ["Label"] }],
code: "<VLabel for='id' />",
options: [{ components: ["VLabel"] }],
errors: [{ messageId: "default" }]
}
]
2 changes: 1 addition & 1 deletion src/rules/__tests__/makeRuleTester.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const makeValidExample = (example) => {
return { filename, code: makeTemplate(example) };
}

return Object.assign(example, { filename });
return Object.assign(example, { filename, code: makeTemplate(example.code) });
};

const makeInvalidExample = (example) => {
32 changes: 23 additions & 9 deletions src/rules/label-has-for.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const {

const controlTypes = ["input", "meter", "progress", "select", "textarea"];

const validateNesting = (node, allowChildren) =>
const validateNesting = (node, allowChildren, controlComponents) =>
node.children.some((child) => {
if (child.rawName === "slot") {
return allowChildren;
@@ -17,35 +17,41 @@ const validateNesting = (node, allowChildren) =>
if (child.type === "VElement") {
return (
!isHiddenFromScreenReader(child) &&
(controlTypes.includes(getElementType(child)) ||
(controlTypes
.concat(controlComponents)
.includes(getElementType(child)) ||
validateNesting(child, allowChildren))
);
}

return false;
});

const validate = (node, rule, allowChildren) => {
const validate = (node, rule, allowChildren, controlComponents) => {
switch (rule) {
case "nesting":
return validateNesting(node, allowChildren);
return validateNesting(node, allowChildren, controlComponents);
case "id":
return getElementAttributeValue(node, "for");
default:
return false;
}
};

const isValidLabel = (node, required, allowChildren) => {
const isValidLabel = (node, required, allowChildren, controlComponents) => {
if (Array.isArray(required.some)) {
return required.some.some((rule) => validate(node, rule, allowChildren));
return required.some.some((rule) =>
validate(node, rule, allowChildren, controlComponents)
);
}

if (Array.isArray(required.every)) {
return required.every.every((rule) => validate(node, rule, allowChildren));
return required.every.every((rule) =>
validate(node, rule, allowChildren, controlComponents)
);
}

return validate(node, required, allowChildren);
return validate(node, required, allowChildren, controlComponents);
};

module.exports = {
@@ -67,6 +73,13 @@ module.exports = {
},
uniqueItems: true
},
controlComponents: {
type: "array",
items: {
type: "string"
},
uniqueItems: true
},
required: {
oneOf: [
{
@@ -116,12 +129,13 @@ module.exports = {
const {
allowChildren = false,
components = [],
controlComponents = [],
required = { every: ["nesting", "id"] }
} = context.options[0] || {};

if (
["label"].concat(components).includes(getElementType(node)) &&
!isValidLabel(node, required, allowChildren)
!isValidLabel(node, required, allowChildren, controlComponents)
) {
context.report({ node, messageId: "default" });
}
Loading