-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(eslint): add eslint support (#89)
* chore(deps): add eslint dependencies * ci: add lint job * chore(eslint): update eslint config * refactor: update code to fix eslint errors * chore: change in to of * Update ci.yml * chore: run prettier, add markdownlint * ci: add lint:md task to lint job, add format job * chore: run format
- Loading branch information
Showing
25 changed files
with
1,284 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with | ||
multi-package repos, or single-package repos to help you version and publish your code. You can find the full | ||
documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
|
||
/** | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
module.exports = { | ||
extends: ['eslint:recommended', 'plugin:github/recommended'], | ||
parserOptions: { | ||
ecmaVersion: 'latest' | ||
}, | ||
env: { | ||
commonjs: true, | ||
node: true | ||
}, | ||
rules: { | ||
'import/no-commonjs': 'off', | ||
'no-shadow': 'off', | ||
'no-unused-vars': [ | ||
'error', | ||
{ | ||
varsIgnorePattern: '^_' | ||
} | ||
] | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['**/*.test.js'], | ||
env: { | ||
jest: true | ||
} | ||
}, | ||
{ | ||
files: ['.eslintrc.js'], | ||
rules: { | ||
'filenames/match-regex': 'off' | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const githubMarkdownOpinions = require('@github/markdownlint-github') | ||
|
||
const options = githubMarkdownOpinions.init({ | ||
// Rules we don't care to enforce (usually stylistic) | ||
'line-length': false, | ||
'blanks-around-headings': false, | ||
'blanks-around-lists': false, | ||
'no-trailing-spaces': false, | ||
'no-multiple-blanks': false, | ||
'no-trailing-punctuation': false, | ||
'single-trailing-newline': false, | ||
'ul-indent': false, | ||
'ul-style': false, | ||
'no-hard-tabs': false, | ||
'first-line-heading': false, | ||
'no-space-in-emphasis': false, | ||
'blanks-around-fences': false | ||
}) | ||
|
||
module.exports = { | ||
config: options, | ||
customRules: ['@github/markdownlint-github'], | ||
outputFormatters: [['markdownlint-cli2-formatter-pretty', {appendLink: true}]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.changeset | ||
node_modules | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
## Require explicit heading level on `<Heading>` component | ||
|
||
The `Heading` component does not require you to use `as` to specify the heading level, as it will default to an `h2` if one isn't specified. This may lead to inaccessible usage if the default is out of order in the existing heading hierarchy. | ||
The `Heading` component does not require you to use `as` to specify the heading level, as it will default to an `h2` if | ||
one isn't specified. This may lead to inaccessible usage if the default is out of order in the existing heading | ||
hierarchy. | ||
|
||
## Rule Details | ||
|
||
This rule enforces using `as` on the `<Heading>` component to specify a heading level (`h1`-`h6`). In addition, it enforces `as` usage to only be used for headings. | ||
This rule enforces using `as` on the `<Heading>` component to specify a heading level (`h1`-`h6`). In addition, it | ||
enforces `as` usage to only be used for headings. | ||
|
||
👎 Examples of **incorrect** code for this rule | ||
|
||
```jsx | ||
import {Heading} from '@primer/react' | ||
|
||
<Heading>Heading without explicit heading level</Heading> | ||
function ExampleComponent() { | ||
return <Heading>Heading without explicit heading level</Heading> | ||
} | ||
``` | ||
|
||
`as` must only be for headings (`h1`-`h6`) | ||
|
||
```jsx | ||
import {Heading} from '@primer/react' | ||
|
||
<Heading as="span">Heading component used as "span"</Heading> | ||
function ExampleComponent() { | ||
return <Heading as="span">Heading component used as "span"</Heading> | ||
} | ||
``` | ||
|
||
👍 Examples of **correct** code for this rule: | ||
|
||
```jsx | ||
import {Heading} from '@primer/react'; | ||
import {Heading} from '@primer/react' | ||
|
||
<Heading as="h2">Heading level 2</Heading> | ||
function ExampleComponent() { | ||
return <Heading as="h2">Heading level 2</Heading> | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
- `skipImportCheck` (default: `false`) | ||
|
||
By default, the `a11y-explicit-heading` rule will only check for `<Heading>` components imported directly from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. | ||
By default, the `a11y-explicit-heading` rule will only check for `<Heading>` components imported directly from | ||
`@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,49 @@ | ||
# Enforce direct parent-child relationship of slot components (direct-slot-children) | ||
|
||
Some Primer React components use a slots pattern under the hood to render subcomponents in specific places. For example, the `PageLayout` component renders `PageLayout.Header` in the header area, and `PageLayout.Footer` in the footer area. These subcomponents must be direct children of the parent component, and cannot be nested inside other components. | ||
|
||
## Rule details | ||
|
||
This rule enforces that slot components are direct children of their parent component. | ||
|
||
👎 Examples of **incorrect** code for this rule: | ||
|
||
```jsx | ||
/* eslint primer-react/direct-slot-children: "error" */ | ||
import {PageLayout} from '@primer/react' | ||
|
||
const MyHeader = () => <PageLayout.Header>Header</PageLayout.Header> | ||
|
||
const App = () => ( | ||
<PageLayout> | ||
<MyHeader /> | ||
</PageLayout> | ||
) | ||
``` | ||
|
||
👍 Examples of **correct** code for this rule: | ||
|
||
```jsx | ||
/* eslint primer-react/direct-slot-children: "error" */ | ||
import {PageLayout} from '@primer/react' | ||
|
||
const MyHeader = () => <div>Header</div> | ||
|
||
const App = () => ( | ||
<PageLayout> | ||
<PageLayout.Header> | ||
<MyHeader /> | ||
</PageLayout.Header> | ||
</PageLayout> | ||
) | ||
``` | ||
|
||
## Options | ||
|
||
- `skipImportCheck` (default: `false`) | ||
|
||
By default, the `direct-slot-children` rule will only check for direct slot children in components that are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is used for internal linting in the [primer/react](https://github.com/prime/react) repository. | ||
|
||
# Enforce direct parent-child relationship of slot components (direct-slot-children) | ||
|
||
Some Primer React components use a slots pattern under the hood to render subcomponents in specific places. For example, | ||
the `PageLayout` component renders `PageLayout.Header` in the header area, and `PageLayout.Footer` in the footer area. | ||
These subcomponents must be direct children of the parent component, and cannot be nested inside other components. | ||
|
||
## Rule details | ||
|
||
This rule enforces that slot components are direct children of their parent component. | ||
|
||
👎 Examples of **incorrect** code for this rule: | ||
|
||
```jsx | ||
/* eslint primer-react/direct-slot-children: "error" */ | ||
import {PageLayout} from '@primer/react' | ||
|
||
const MyHeader = () => <PageLayout.Header>Header</PageLayout.Header> | ||
|
||
const App = () => ( | ||
<PageLayout> | ||
<MyHeader /> | ||
</PageLayout> | ||
) | ||
``` | ||
|
||
👍 Examples of **correct** code for this rule: | ||
|
||
```jsx | ||
/* eslint primer-react/direct-slot-children: "error" */ | ||
import {PageLayout} from '@primer/react' | ||
|
||
const MyHeader = () => <div>Header</div> | ||
|
||
const App = () => ( | ||
<PageLayout> | ||
<PageLayout.Header> | ||
<MyHeader /> | ||
</PageLayout.Header> | ||
</PageLayout> | ||
) | ||
``` | ||
|
||
## Options | ||
|
||
- `skipImportCheck` (default: `false`) | ||
|
||
By default, the `direct-slot-children` rule will only check for direct slot children in components that are imported | ||
from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is used for internal | ||
linting in the [primer/react](https://github.com/prime/react) repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.