Git Product home page Git Product logo

eslint-plugin-primer-react's Introduction

Primer CSS

The CSS implementation of GitHub's Primer Design System

Documentation

⚠️ The documentation of this repo is not maintained anymore. Please raise any documentation-specific pull requests in primer.style/design

Our documentation site lives at primer.style/css. You'll be able to find detailed documentation on getting started, all of the components, our theme, our principles, and more.

Install

This repository is distributed with npm. After installing npm, you can install @primer/css with this command:

npm install --save @primer/css

Usage

The included source files are written in Sass using SCSS syntax. After installing with npm, you can add your project's node_modules directory to your Sass include paths (AKA load paths in Ruby), then import it like this:

@import "@primer/css/index.scss";

You can import individual Primer modules directly from the @primer/css package:

@import "@primer/css/core/index.scss";
@import "@primer/css/product/index.scss";
@import "@primer/css/marketing/index.scss";

Development

See DEVELOP.md for development docs.

Releasing (for GitHub staff)

You can find docs about our release process in RELEASING.md.

License

MIT © GitHub

eslint-plugin-primer-react's People

Contributors

broccolinisoup avatar camertron avatar colebemis avatar dependabot[bot] avatar dmarcey avatar github-actions[bot] avatar jfuchs avatar joshblack avatar keithamus avatar khiga8 avatar langermank avatar lukasoppermann avatar pksjce avatar primer-css avatar sferadev avatar siddharthkp avatar tylerjdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

eslint-plugin-primer-react's Issues

Add lint rules for recommended imports and prop usage

It'd be great to have two specific rules that we can add to over time:

  • use-preferred-imports
  • use-preferred-props

These rules would encapsulate our preferred way to import components and prop usage for a component. This could help with migrating components across entrypoints or prop renames.

Create a lint rule for disabled controls

Summary

We often have to deal with disabled controls in Primer which are typically inaccessible to most users. If we could create a rule that would help stem that usage, then it might reduce the amount of inaccessible patterns that are commonly used with the disabled attribute.

Idea

We cannot restrict usage of the disabled attribute outright, as it may be a good option in some cases. Since there are many different nuances for how and when this attribute is used, we should restrict this rule to only be applied in specific cases.

In forms

We provide guidance against disabling save/submit buttons in forms and instead provide a reason as to why the submission isn't successful. We could potentially create a rule that throws a violation against disabled submit buttons used within a <form>, or similar form-based components.

Example of bad usage:

<form>
  <label>Name
    <input type="text" name="name" required />
  </label>

  <label>
    Bio
    <textarea name="bio" rows="5" />
  </label>
  
  <!-- The control is disabled, but provides no explanation as to why -->
  <button type="submit" disabled>Save</button>
</form>

We could warn in instances where disabled is used for the submit control, much like in the example above.

As suggestions

ESLint allows you to provide suggestions to patterns without throwing an error. We could utilize this to steer developers away from disabled, by encouraging them to look into using a more accessible pattern that will fits their needs.

Create a lint rule that restricts tag usage

Some components allow a as prop to be set. This flexibility can lead to non-semantic component usage which is very detrimental to accessibility.

For example, a <Heading> component should only ever render with a heading tag. However, it can currently be rendered with any tag like <p>.

Until a system-level update is made to define an allowlist for each component that accepts prop, we should restrict as values with a lint rule.

If we can make a system-level change, that would be preferable, but I'm not sure what work is involved for that.

Related Slack convo GitHub staff-only

Make sure `recommended.js` is up-to-date and dependecies are up-to-date

The component to tag mappings in recommended.js have not been updated for a while, and is overdue for a review.

In addition, this library is behind on jsx-a11y and eslint-plugin-github dependency updates.

We have a mapping that is used in eslint-plugin-jsx-a11y and a mapping that is used in eslint-plugin-github. The latter should be deprecated since it was an experimental feature that is deprecated in the latest eslint-plugin-github.

  • Are there any component to tag mappings that should be newly added? (Notably, jsx-a11y supports 1:1 component to tag mapping). However, we should be wary of adding some mappings that could raise a false positive. For example, if we map Avatar to img, but it already sets alt internally default, the ESLint rule may incorrectly flag that there's a missing alt.
  • Are there any component to tag mappings that should be removed?

Acceptance criteria

  • Bump eslint-plugin-github and eslint-plugin-jsx-a11y dependency to the latest
  • Ensure that the configs are up-to-date.

[Spike] Create a lint rule that suggests a more appropriate component for `as`

I think it'd be helpful to have a linter that suggests a more appropriate element based on the as prop.

I've noticed instances of <Box as="h1"> (or some other heading level). I think this is a misuse of Box, and a linter could suggest using a <Heading>. If there are other common component misuse, a linter could catch and suggest a more appropriate component.

This isn't directly tied to accessibility, but components being used in a predictable manner is important.

Create a lint rule that restricts `aria-label` or `aria-labelledby` usage based on tag

We should never allow aria-label or aria-labelledby on roles that do not support it. I've noticed instances of <Text aria-label> and <Box aria-label> in the codebase, which should be flagged.

I think we could flag inappropriate aria-label misuse based on what the as is set as, the role, and the default tag for the component.

Examples of what should be flagged:

<Heading aria-label="Some text">
<Box as="p" aria-label="Some text">
<Text aria-labelledby="some-id">

eslint-plugin-jsx-a11y has limited support for linting (polymorphic) components so unfortunately we aren't getting the a11y linting we need. We could get around this with a custom rule in this plugin.

Create an lint rule to warn deprecated component usage

To increase the adoption of our accessible/improved components, we want to add a lint rule that warns consumers if they stay using the deprecated version of the components.

We want to move away from

import { Tooltip } from '@primer/react/deprecated'

to

import { Tooltip } from '@primer/react/experimental'

[Idea] Opinionated rule that requires `as` to be set for `<Heading>`

Currently <Heading> defaults to h3 so consumers don't need to explicitly set as.

Default example:

<Heading>Some heading</Heading>

Should heading as always be set to ensure consumers are intentional, rather than obscuring by default?

Here is an example with the same default heading but with level explicitly set:

<Heading as="h3">Some heading</Heading>

cc: @TylerJDev

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.