Skip to content

Commit 55f10dc

Browse files
authored
Merge pull request #284 from github/kh-add-docs-for-component-config
Update README with component mapping setting
2 parents 9d77cf3 + 2164129 commit 55f10dc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ The available configs are:
4141
- `typescript`
4242
- Useful rules when writing TypeScript.
4343

44+
### Component mapping (Experimental)
45+
46+
_Note: This is experimental and subject to change._
47+
48+
The `react` config includes rules which target specific HTML elements. You may provide a mapping of custom components to an HTML element in your `eslintrc` configuration to increase linter coverage.
49+
50+
For each component, you may specify a `default` and/or `props`. `default` may make sense if there's a 1:1 mapping between a component and an HTML element. However, if the HTML output of a component is dependent on a prop value, you can provide a mapping using the `props` key. To minimize conflicts and complexity, this currently only supports the mapping of a single prop type.
51+
52+
```json
53+
{
54+
"settings": {
55+
"github": {
56+
"components": {
57+
"Box": { "default": "p" },
58+
"Link": { "props": {"as": { "undefined": "a", "a": "a", "button": "button"}}},
59+
}
60+
}
61+
}
62+
}
63+
```
64+
65+
This config will be interpreted in the following way:
66+
67+
- All `<Box>` elements will be treated as a `p` element type.
68+
- `<Link>` without a defined `as` prop will be treated as a `a`.
69+
- `<Link as='a'>` will treated as an `a` element type.
70+
- `<Link as='button'>` will be treated as a `button` element type.
71+
- `<Link as='summary'>` will be treated as the raw `Link` type because there is no configuration set for `as='summary'`.
72+
4473
### Rules
4574

4675
- [Array Foreach](./docs/rules/array-foreach.md)

lib/configs/react.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
2-
env: {
3-
browser: true
2+
parserOptions: {
3+
sourceType: 'module',
4+
ecmaFeatures: {
5+
jsx: true
6+
}
47
},
58
plugins: ['github', 'jsx-a11y'],
69
extends: ['plugin:jsx-a11y/recommended'],

0 commit comments

Comments
 (0)