Code Monkey home page Code Monkey logo

stylelint-a11y's Introduction

@double-great/stylelint-a11y

Installation and usage

npm i --save-dev stylelint @double-great/stylelint-a11y

Create the .stylelintrc.json config file (or open the existing one), add stylelint-a11y to the plugins array and the rules you need to the rules list. All rules from stylelint-a11y need to be namespaced with a11y.

Please refer to stylelint docs for the detailed info on using this linter.

Rules

Rule ID Description
content-property-no-static-value Disallow unaccessible CSS generated content in pseudo-elements
font-size-is-readable Disallow font sizes less than 15px
line-height-is-vertical-rhythmed Disallow not vertical rhythmed line-height
media-prefers-reduced-motion Require certain styles if the animation or transition in media features Recommended, Fixable
media-prefers-color-scheme Require implementation of certain styles for selectors with colors.
no-display-none Disallow content hiding with display: none property
no-obsolete-attribute Disallow obsolete attribute using
no-obsolete-element Disallow obsolete selectors using
no-spread-text Require width of text in a comfortable range
no-outline-none Disallow outline clearing Recommended
no-text-align-justify Disallow content with text-align: justify
selector-pseudo-class-focus Require or disallow a pseudo-element to the selectors with :hover Recommended, Fixable

Recommended config

Add recommended configuration by adding the following to extends in your stylelint configuration:

@double-great/stylelint-a11y/recommended

This shareable config contains the following:

{
  "plugins": ["@double-great/stylelint-a11y"],
  "rules": {
    "a11y/media-prefers-reduced-motion": true,
    "a11y/no-outline-none": true,
    "a11y/selector-pseudo-class-focus": true
  }
}

Since it adds stylelint-a11y to plugins, you don't have to do this yourself when extending this config.

Help out

There work on the plugin's rules is still in progress, so if you feel like it, you're welcome to help out in any of these (the plugin follows stylelint guidelines so most part of this is based on its docs):

  • Create, enhance, and debug rules (see stylelint's guide to "Working on rules").
  • Improve documentation.
  • Chime in on any open issue or pull request.
  • Open new issues about your ideas on new rules, or for how to improve the existing ones, and pull requests to show us how your idea works.
  • Add new tests to absolutely anything.
  • Work on improving performance of rules.
  • Contribute to stylelint
  • Spread the word.

We communicate via issues and pull requests.

There is also stackoverflow, which would be the preferred QA forum.

stylelint-a11y's People

Contributors

yozhikm avatar jsnmrs avatar katydecorah avatar igorkamyshev avatar uncleseneca avatar dependabot[bot] avatar ybiquitous avatar hudochenkov avatar coliff avatar silvenon avatar mikerourke avatar pascalduez avatar scottgruber avatar thibaudcolas avatar baradusov avatar

Stargazers

 avatar Adrian D. Alvarez avatar Daniel Bannert avatar David J Nevin avatar

Watchers

Alain avatar

Forkers

mikerourke

stylelint-a11y's Issues

Switch to TypeScript

@jsnmrs I think you may have fun switching this project to use TypeScript ๐Ÿ˜‡ if you're interested, I can create a starter pull request for you and/or steps.

`a11y/media-prefers-reduced-motion` keeps adding media queries.

I have this scss mixin here:

@mixin safe-hover {
  @media (hover: hover) {
    &:hover,
    &:focus {
      background-color: $colorSecondary;
      transition: all 0.15s;
    }

    @media screen and (prefers-reduced-motion: reduce) {
      &:hover,
      &:focus {
        background-color: $colorSecondary;
        transition: none;
      }
    }
  }
}

And the auto fix keeps adding the same media query to it. It seems like the plugin does not check if nest media query is already there.

Add more accessibility rules

https://github.com/thibaudcolas/stylelint-accessible/tree/main/lib/rules has a few overlapping rules so I think it'd make sense to work with the author to implement the other rules here.

Potential rules to implement:

  • font-size-relative
  • no-float
  • no-forced-color-adjust-none.js
  • no-text-overflow-ellipsis

Also, similar to the no-display-none rule, a no-visibility-hidden rule can be added.

"you shouldn't use visibility:hidden or display:none, because they do hide content from screen readers. Unless of course, there is a good reason why you want this content to be hidden from screen readers."
https://developer.mozilla.org/en-US/docs/Learn/Accessibility/CSS_and_JavaScript#hiding_things

Bug: Could not find "@double-great/stylelint-a11y/recommended"

I'm trying to use the recommended config but receive following error:

Error: Could not find "@double-great/stylelint-a11y/recommended". Do you need to install the package or use the "configBasedir" option?
    at configurationError (.../node_modules/stylelint/lib/utils/configurationError.mjs:12:49)
    at getModulePath (.../node_modules/stylelint/lib/utils/getModulePath.mjs:29:9)
    at loadExtendedConfig (.../node_modules/stylelint/lib/augmentConfig.mjs:217:21)
    at extendConfig (.../node_modules/stylelint/lib/augmentConfig.mjs:185:25)
    at augmentConfigBasic (.../node_modules/stylelint/lib/augmentConfig.mjs:58:26)
    at augmentConfigFull (.../node_modules/stylelint/lib/augmentConfig.mjs:112:30)
    at Object.transform (.../node_modules/stylelint/lib/getConfigForFile.mjs:52:37)
    at search (...\node_modules\cosmiconfig\dist\Explorer.js:53:54)
    at async search (...\node_modules\cosmiconfig\dist\Explorer.js:71:28)
    at async search (...\node_modules\cosmiconfig\dist\Explorer.js:71:28)

.stylelintrc.js

module.exports = {
  extends: ["@double-great/stylelint-a11y/recommended"],
  rules: {},
};

Command to run:

npx stylelint .

Happens with NPM and Yarn.

Versions:

  • stylelint 16.2.1
  • @double-great/stylelint-a11y - tested versions 3.0.0, 3.0.1, 3.0.2

OS: Win11

Adding rules directly works, for example this:

module.exports = {
  plugins: ["@double-great/stylelint-a11y"],

  rules: {
    "a11y/media-prefers-reduced-motion": true,
  },
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.