├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── discussion.md
│ └── feature_request.md
├── PULL_REQUEST_TEMPLATE.md
├── stale.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── .husky
└── pre-commit
├── LICENSE
├── README.md
├── docs
├── .gitkeep
├── Browser Support.md
├── Getting Started.md
└── Style Guide.md
├── fixtures
└── app
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .prettierrc
│ └── package.json
├── lerna.json
├── package.json
├── packages
├── eslint-config-vtex-react
│ ├── .eslintrc
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── demo
│ │ ├── .eslintrc
│ │ ├── Component.tsx
│ │ └── package.json
│ ├── gatsby.js
│ ├── index.js
│ ├── io.js
│ ├── native.js
│ ├── package.json
│ └── rules
│ │ ├── react-a11y.js
│ │ ├── react-hooks.js
│ │ └── react.js
├── eslint-config-vtex
│ ├── .eslintrc
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── demo
│ │ ├── index.js
│ │ ├── index.ts
│ │ └── package.json
│ ├── index.js
│ ├── lib
│ │ └── utils.js
│ ├── package.json
│ └── rules
│ │ ├── best-practices.js
│ │ ├── errors.js
│ │ ├── imports.js
│ │ ├── node.js
│ │ ├── prettier.js
│ │ ├── style.js
│ │ ├── tests.js
│ │ ├── typescript.js
│ │ └── variables.js
├── eslint-plugin-vtex
│ ├── .gitignore
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── docs
│ │ └── rules
│ │ │ ├── consistent-props-type.md
│ │ │ ├── prefer-early-return.md
│ │ │ └── prefer-use-effect-named-callback.md
│ ├── package.json
│ ├── src
│ │ ├── configs
│ │ │ └── recommended.ts
│ │ ├── createRule.ts
│ │ ├── index.ts
│ │ ├── rules
│ │ │ ├── __tests__
│ │ │ │ ├── consistent-props-type.test.ts
│ │ │ │ ├── prefer-early-return.test.ts
│ │ │ │ └── prefer-use-effect-named-callback.test.ts
│ │ │ ├── consistent-props-type.ts
│ │ │ ├── prefer-early-return.ts
│ │ │ └── prefer-use-effect-named-callback.ts
│ │ └── utils
│ │ │ ├── estree
│ │ │ ├── getFunctionNodeName.ts
│ │ │ ├── isFunctionNode.ts
│ │ │ └── isInsideAnotherFunction.ts
│ │ │ └── react
│ │ │ └── isComponentName.ts
│ ├── test
│ │ └── babel.config.js
│ └── tsconfig.json
├── prettier-config
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── index.js
│ └── package.json
└── tsconfig
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── package.json
│ └── tsconfig.json
├── scripts
└── bootstrap-typescript.sh
├── tsconfig.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | # rules/
2 | node_modules/
3 | coverage/
4 | dist/
5 | fixtures/
6 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "vtex",
3 | "root": true
4 | }
5 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @vtex/front-end-dx-guild
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | ---
5 |
6 | **Describe the bug**
7 | A clear and concise description of what the bug is.
8 |
9 | **To Reproduce**
10 | Steps to reproduce the behavior:
11 |
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Desktop (please complete the following information):**
24 |
25 | - OS: [e.g. iOS]
26 | - Browser [e.g. chrome, safari]
27 | - Version [e.g. 22]
28 |
29 | **Smartphone (please complete the following information):**
30 |
31 | - Device: [e.g. iPhone6]
32 | - OS: [e.g. iOS8.1]
33 | - Browser [e.g. stock browser, safari]
34 | - Version [e.g. 22]
35 |
36 | **Additional context**
37 | Add any other context about the problem here.
38 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/discussion.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Discussion
3 | about: Questions and discussions about best practices and patterns
4 | ---
5 |
6 | **What is to be discussed?**
7 |
8 |
9 | **Describe the solution you'd like**
10 |
11 |
12 | **How we do this today?**
13 |
14 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | ---
5 |
6 | **Is your feature request related to a problem? Please describe.**
7 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
8 |
9 | **Describe the solution you'd like**
10 | A clear and concise description of what you want to happen.
11 |
12 | **Describe alternatives you've considered**
13 | A clear and concise description of any alternative solutions or features you've considered.
14 |
15 | **Additional context**
16 | Add any other context or screenshots about the feature request here.
17 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Summary
2 |
3 |
4 |
5 | ## How to test
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Configuration for probot-stale - https://github.com/probot/stale
2 |
3 | # Number of days of inactivity before an Issue or Pull Request becomes stale
4 | daysUntilStale: 7
5 |
6 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
7 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8 | daysUntilClose: false
9 |
10 | # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
11 | onlyLabels: []
12 |
13 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
14 | exemptLabels:
15 | - todo
16 | - documentation
17 | - fresh
18 |
19 | # Set to true to ignore issues in a project (defaults to false)
20 | exemptProjects: false
21 |
22 | # Set to true to ignore issues in a milestone (defaults to false)
23 | exemptMilestones: false
24 |
25 | # Set to true to ignore issues with an assignee (defaults to false)
26 | exemptAssignees: false
27 |
28 | # Label to use when marking as stale
29 | staleLabel: stale
30 |
31 | # Comment to post when marking as stale. Set to `false` to disable
32 | markComment: >
33 | This issue has been automatically marked as stale because it has not had
34 | recent activity. It will be closed if no further activity occurs.
35 |
36 | You can add the `fresh` label to prevent me from taking any action.
37 |
38 | If this is a discussion thread, the most voted option will be final. Thank you for your contributions.
39 |
40 | # Comment to post when removing the stale label.
41 | # unmarkComment: >
42 | # Your comment here.
43 |
44 | # Comment to post when closing a stale Issue or Pull Request.
45 | # closeComment: >
46 | # Your comment here.
47 |
48 | # Limit the number of actions per hour, from 1-30. Default is 30
49 | limitPerRun: 30
50 | # Limit to only `issues` or `pulls`
51 | only: issues
52 |
53 | # Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
54 | # pulls:
55 | # daysUntilStale: 30
56 | # markComment: >
57 | # This pull request has been automatically marked as stale because it has not had
58 | # recent activity. It will be closed if no further activity occurs. Thank you
59 | # for your contributions.
60 |
61 | # issues:
62 | # exemptLabels:
63 | # - confirmed
64 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - main
7 | push:
8 | branches:
9 | - main
10 |
11 | jobs:
12 | Lint:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v1
16 | - uses: actions/setup-node@v1
17 | with:
18 | node-version: '18'
19 | - name: Install dependencies
20 | run: yarn install --frozen-lockfile
21 |
22 | - name: Run build
23 | run: yarn build
24 |
25 | - name: Run lint
26 | run: yarn lint
27 |
28 | 'E2E_Tests':
29 | runs-on: ubuntu-latest
30 | services:
31 | verdaccio:
32 | image: verdaccio/verdaccio:4.0.0
33 | ports:
34 | - 4873:4873
35 | steps:
36 | - uses: actions/checkout@v1
37 | - uses: actions/setup-node@v1
38 | with:
39 | node-version: '18'
40 |
41 | - name: Install dependencies
42 | run: yarn install --frozen-lockfile
43 |
44 | - name: Verdaccio login
45 | run: |
46 | npx npm-cli-adduser \
47 | -u username \
48 | -p pass \
49 | -e username@email.com \
50 | -r http://localhost:4873 || true
51 |
52 | - name: Configure git
53 | run: |
54 | git config --global user.name 'Verdaccio User'
55 | git config --global user.email 'username@email.com'
56 |
57 | - name: Get changed packages
58 | id: changed-packages
59 | run: |
60 | changed_packages=$(yarn -s lerna list --since | sed 's/$/\@0.0.0-verdaccio/' | xargs echo)
61 |
62 | echo "::set-output name=PACKAGES::$changed_packages"
63 |
64 | - name: Publish packages
65 | run: |
66 | yarn lerna publish \
67 | '0.0.0-verdaccio' \
68 | --registry http://localhost:4873 \
69 | --no-git-tag-version \
70 | --no-push \
71 | --yes
72 |
73 | - uses: actions/setup-node@v1
74 | with:
75 | node-version: '14'
76 |
77 | - name: Install dependencies
78 | run: yarn --cwd fixtures/app install --no-lockfile
79 |
80 | - name: Install packages and run test
81 | if: steps.changed-packages.outputs.PACKAGES
82 | run: |
83 | yarn --cwd fixtures/app add \
84 | --registry http://localhost:4873 \
85 | -D ${{ steps.changed-packages.outputs.PACKAGES }}
86 | yarn --cwd fixtures/app test
87 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### SublimeText ###
2 | *.sublime-workspace
3 |
4 | ### VS Code ###
5 | *.vscode
6 |
7 | ### OSX ###
8 | .DS_Store
9 | .AppleDouble
10 | .LSOverride
11 | Icon
12 |
13 | # Thumbnails
14 | ._*
15 |
16 | # Files that might appear on external disk
17 | .Spotlight-V100
18 | .Trashes
19 |
20 | ### Windows ###
21 | # Windows image file caches
22 | Thumbs.db
23 | ehthumbs.db
24 |
25 | # Folder config file
26 | Desktop.ini
27 |
28 | # Recycle Bin used on file shares
29 | $RECYCLE.BIN/
30 |
31 | # App specific
32 | node_modules/
33 | docs/_book/
34 | .tmp
35 | .idea
36 | npm-debug.log
37 | .build/
38 | dist
39 | build
40 | lerna-debug.log
41 | yarn-error.log
42 | *.orig
43 | package-lock.json
44 | config-dump.json
45 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn lint-staged
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 VTEX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Typescript Standards
2 |
3 | Main repository for VTEX's Typescript standards. Issues should be used to start discussions about standards and patterns. PRs are welcome after being rightfully discussed.
4 |
5 | ## Content
6 |
7 | ##### `docs/`
8 |
9 | - [Style Guide](/docs/Style%20Guide.md) - VTEX Javascript/Typescript style guide
10 | - [Getting Started](/docs/Getting%20Started.md) - Getting starting guide to configure and automate our tooling process
11 | - [Browser Support](/docs/Browser%20Support.md) - VTEX browser support documentation
12 |
13 | ##### `packages/`
14 |
15 | - [eslint-config-vtex](/packages/eslint-config-vtex) - base eslint rule preset
16 | - [eslint-config-vtex-react](/packages/eslint-config-vtex-react) - eslint rule preset for react projects
17 | - [eslint-plugin-vtex](/packages/eslint-plugin-vtex) - eslint plugin with VTEX custom rules
18 | - [prettier-config](/packages/prettier-config) - prettier preset of all front-end projects
19 | - [tsconfig](/packages/tsconfig) - base tsconfig for all typescript projects
20 |
21 | ## Add these packages to a new project
22 |
23 | ### Bootstrap on a new node and typescript project
24 |
25 | > If you're not using Bash, change `/bin/bash` to your shell's executable path.
26 |
27 | ```bash
28 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/vtex/typescript/master/scripts/bootstrap-typescript.sh)"
29 | ```
30 |
31 | > **Warning**: This will **override** the following configuration files: `.prettierrc`, `.eslintrc` and `tsconfig.json`.
32 |
33 | ## Contributing
34 |
35 | Nothing is written in stone, so if there's some kind of rule or pattern that you wish to discuss or implement, we encourage an open discussion via this [repository issues](/issues). The project use labels to keep everything organized and easy-to-find:
36 |
37 | - `discussion` - discussion thread;
38 | - `style` - related to code style, something that there's no wrong or right;
39 | - `practices/patterns` - related to good coding practices that should be standardized and documented;
40 | - `documentation` - a generic documentation issue;
41 | - `todo` - common TODO item, with no explicit SLA.
42 |
43 | Feel free to use more than one label in an issue, but try keeping them semantic to help developers.
44 |
45 | ### Working with the packages
46 |
47 | This project uses `lerna` with `yarn` workspaces, so it's highly recommended to read at least the [Lerna documentation](https://github.com/lerna/lerna).
48 |
49 | #### Bootstrap the repository
50 |
51 | Running `yarn` will automatically install all the dependencies for all packages and link them together when needed.
52 |
53 | ```bash
54 | yarn
55 | ```
56 |
57 | #### Executing commands
58 |
59 | To run a `package.json` script on all packages, you can use:
60 |
61 | ```bash
62 | lerna run {scriptName}
63 | # will run the scriptName script on all package directories
64 | ```
65 |
66 | If you want to only run on some packages, pass a `--scope=package-name` to the command above. For more instructions, see the [`lerna run` documentation](https://github.com/lerna/lerna/tree/master/commands/run#readme).
67 |
68 | ```bash
69 | lerna run --scope="eslint-*" test
70 | # run the test script on all packages that match the pattern above
71 | ```
72 |
73 | The same can be done for regular shell programs with the `lerna exec` command:
74 |
75 | ```bash
76 | lerna exec "pwd"
77 | # will print the pwd of all package directories
78 | ```
79 |
80 | _Note: The quotes are not needed if your command doesn't have a string with spaces._
81 |
82 | #### Releasing new versions
83 |
84 | For every release, there should be at least one new changelog entry for every modified package. This repository follows the [keep a changelog](https://keepachangelog.com/en/1.0.0/) format. The [`chan`](https://github.com/geut/chan) CLI can be used to help adding changelog entries:
85 |
86 | ```bash
87 | chan fixed "Fix that nasty potato bug"
88 | ```
89 |
90 | It's also possible to run the command on multiple packages with the `lerna exec` command:
91 |
92 | ```bash
93 | lerna exec "chan fixed 'Fix that nasty potato bug'"
94 | # note the quotes
95 | ```
96 |
97 | Every package has a `version` script that will automatically update their changelog with the new version and entries whenever `lerna publish` or `lerna version` is used.
98 |
99 | Relevant commands:
100 |
101 | - [`lerna version`](https://github.com/lerna/lerna/blob/master/commands/version/README.md) - Only update versions without publishing the packages.
102 | - [`lerna publish`](https://github.com/lerna/lerna/blob/master/commands/publish/README.md) - Update the version and publish the packages.
103 |
--------------------------------------------------------------------------------
/docs/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vtex/typescript/e97bc405c546a3b8f0faf6c49d5cf4b7bc950c2a/docs/.gitkeep
--------------------------------------------------------------------------------
/docs/Browser Support.md:
--------------------------------------------------------------------------------
1 | # Browser Support
2 |
3 |
4 |
5 |
6 |
7 | - [Guidelines](#guidelines)
8 | - [Polyfills](#polyfills)
9 |
10 |
11 |
12 | VTEX browser support is split in two contexts: `storefront` and `admin areas`.
13 |
14 | For `storefronts`, we strive to support all major browsers all the way to IE 11:
15 |
16 | ```text
17 | # Browserslist example (date 2020-01-29)
18 | IE 11
19 | Edge 17+
20 | Safari 8+
21 | Chrome 77+
22 | Firefox 70+
23 | ```
24 |
25 | | [
](http://godban.github.io/browsers-support-badges/)
IE / Edge | [
](http://godban.github.io/browsers-support-badges/)
Firefox | [
](http://godban.github.io/browsers-support-badges/)
Chrome | [
](http://godban.github.io/browsers-support-badges/)
Safari |
26 | | --------- | --------- | --------- | --------- |
27 | | IE11, Edge| last 10 versions| last 10 versions| last 4 versions
28 |
29 | _Note: even though we support older browsers such as IE 11 and Safari 8, the layout may slightly vary due to CSS browser support._
30 |
31 | For `admin areas`, the main targets are evergreen browsers, such as Firefox, Chrome, the new Edge, etc:
32 |
33 | ```text
34 | # Browserslist example (date 2020-01-29)
35 | Edge 17+
36 | Safari 12.1
37 | Chrome 77+
38 | Firefox 70+
39 | ```
40 |
41 | | [
](http://godban.github.io/browsers-support-badges/)
IE / Edge | [
](http://godban.github.io/browsers-support-badges/)
Firefox | [
](http://godban.github.io/browsers-support-badges/)
Chrome | [
](http://godban.github.io/browsers-support-badges/)
Safari |
42 | | --------- | --------- | --------- | --------- |
43 | | Edge| last 10 versions| last 10 versions| last 2 versions
44 |
45 | ## Guidelines
46 |
47 | It's usually in a dev's heart the desire to use the newest Javascript feature or a new fancy CSS property, such as `display: grid`, `position: sticky`, `Map()`, `Set()`, etc. However, _browser support_ and _cross-browser compatibility_ are the first concerns that have to come to the developer's mind. Make sure to always check `MDN` and `Can I Use` for the current support of the desired functionality.
48 |
49 | - [MDN - Mozilla Developer Network](https://developer.mozilla.org/)
50 | - [Can I Use](https://caniuse.com/)
51 |
52 | If the functionality is not well supported and yet it's needed for some _important_ reason, a [polyfill or ponyfill](https://ponyfoo.com/articles/polyfills-or-ponyfills) can help solving the problem. Keep in mind that polyfills add extra weight to the store assets and not always perform as good as their native implementations.
53 |
54 | ## Polyfills
55 |
56 | > A polyfill is a piece of code used to provide modern functionality on older browsers that do not natively support it.
57 |
58 | To be possible to write and use modern Javascript and CSS features while supporting all the way to IE 11, some polyfills are automatically added **only** to VTEX IO stores:
59 |
60 | - [`Array.from()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
61 | - [`Array.prototype.fill()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
62 | - [`Array.prototype.find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
63 | - [`Array.prototype.findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
64 | - [`Array.prototype.includes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
65 | - [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
66 | - [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
67 | - [`IntersectionObserver()`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver)
68 | - [`Intl.~locale.${locale}`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Locale)
69 | - [`Map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
70 | - [`Number.isInteger()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
71 | - [`Number.isNaN()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
72 | - [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
73 | - [`Object.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
74 | - [`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
75 | - [`Object.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
76 | - [`Promise()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
77 | - [`Set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
78 | - [`String.prototype.endsWith()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
79 | - [`String.prototype.includes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
80 | - [`String.prototype.startsWith()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
81 | - [`Symbol()`](https://developer.mozilla.org/en-US/docs/Glossary/Symbol)
82 | - [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL)
83 | - [`WeakMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
84 |
--------------------------------------------------------------------------------
/docs/Getting Started.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 |
4 |
5 |
6 |
7 | - [IO Apps](#io-apps)
8 | - [Manual Setup](#manual-setup)
9 | - [1 - Installing and configuring the essential packages](#1-installing-and-configuring-the-essential-packages)
10 | - [1.1 - For `react` projects](#11-for-react-projects)
11 | - [1.2 - For `Typescript` projects](#12-for-typescript-projects)
12 | - [2 - Creating tasks](#2-creating-tasks)
13 | - [3 - Automating](#3-automating)
14 | - [CI Automation](#ci-automation)
15 |
16 |
17 |
18 | ## IO Apps
19 |
20 | For IO applications, the toolbelt command `vtex setup` should get you going. It installs the appropriate linting and formatting packages for your project.
21 |
22 | If you're configuring an already existing project, running `vtex setup` may not be enough and you'll need to update your project's files. Check the manual setup tutorial below to see these steps.
23 |
24 | ## Manual Setup
25 |
26 | VTEX `Javascript`/`Typescript` style guide consists of some separate packages:
27 |
28 | - [`@vtex/prettier-config`](/packages/prettier-config) - VTEX's unified `prettier` configuration. Responsible for automatically formatting all javascript code.
29 | - [`eslint-config-vtex`](/packages/eslint-config-vtex) - VTEX's base `eslint` configuration. Responsible for static analyzing every `Javascript` code and guaranteeing a baseline of code quality and good practices.
30 | - [`eslint-config-vtex-react`](/packages/eslint-config-vtex-react) - An extension of the base configuration with specific rules for react applications.
31 | - [`@vtex/tsconfig`](/packages/tsconfig) - VTEX's unified `tsconfig.json` preset for every `Typescript` project.
32 |
33 | Every project which uses `Javascript` or `Typescript` must have at least `eslint-config-vtex` and `@vtex/prettier-config` installed. Please check their _README_ for any specific package questions.
34 |
35 | ### 1 - Installing and configuring the essential packages
36 |
37 | First of all we need to install the _basis of everything_:
38 |
39 | ```bash
40 | $ yarn add -D eslint prettier eslint-config-vtex @vtex/prettier-config
41 | ```
42 |
43 | Then create their configuration files at the root of your project:
44 |
45 | `.eslintrc`:
46 |
47 | ```jsonc
48 | { "extends": "vtex" }
49 | ```
50 |
51 | `.prettierrc`:
52 |
53 | ```jsonc
54 | "@vtex/prettier-config"
55 | ```
56 |
57 | > _Note: yes, it's a string literal in a JSON file._
58 |
59 | #### 1.1 - For `react` projects
60 |
61 | You can install `eslint-config-vtex-react` instead of the base configuration.
62 |
63 | Then use the preset in your project's `.eslintrc`:
64 |
65 | `.eslintrc`:
66 |
67 | ```jsonc
68 | { "extends": "vtex-react" }
69 | ```
70 |
71 | We also provide two other presets:
72 |
73 | - `vtex-react/io` - Specific for VTEX IO React apps.
74 | - `vtex-react/native` - Specific for `react-native` apps.
75 |
76 | Make sure to use the appropriate preset for your context.
77 |
78 | #### 1.2 - For `Typescript` projects
79 |
80 | ```bash
81 | $ yarn add -D typescript @vtex/tsconfig
82 | ```
83 |
84 | Then create a `tsconfig.json` at the root of your project which extends the config:
85 |
86 | ```jsonc
87 | {
88 | "extends": "@vtex/tsconfig"
89 | }
90 | ```
91 |
92 | ### 2 - Creating tasks
93 |
94 | After installing the essential tools, it's time for creating shortcut tasks for us to be able to lint and format our projects. Add the following scripts to your project's **root** `package.json`:
95 |
96 | ```jsonc
97 | {
98 | //...,
99 | "scripts": {
100 | //...,
101 | "lint": "eslint --ext js,jsx,ts,tsx .",
102 | "format": "prettier --write \"**/*.{ts,js,json}\""
103 | },
104 | ...
105 | }
106 | ```
107 |
108 | Now you have two (and a half) commands:
109 |
110 | - `yarn lint` - Will lint all your files according to VTEX standards.
111 | - `yarn lint --fix` - Will lint all your project files and fix auto-fixable errors along the way :tada:.
112 | - `yarn format` - Will format all your files according to VTEX standards.
113 |
114 | ### 3 - Automating
115 |
116 | Ok, our tools are installed, configured, we have a quick and easy-to-use commands to adequate our project to VTEX's standard, what more can be done? **Automation!**
117 |
118 | A developer shouldn't have to think about linting and formatting, usually their IDE is configured to automatically do both things while someone is coding. However, not every IDE is equal nor rightly configured, so we need a way to automate these process to guarantee VTEX's standards.
119 |
120 | Install `husky` and `lint-staged` in the root of your project:
121 |
122 | ```bash
123 | $ yarn add -D husky lint-staged
124 | ```
125 |
126 | - `husky` is used to easily configure [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
127 | - `lint-staged` is used together with `husky` to lint and format _ONLY_ files that are being commited. No need to run on the whole project.
128 |
129 | Then, add these configuration objects to your project's **root** `package.json`:
130 |
131 | ```jsonc
132 | {
133 | //...,
134 | "husky": {
135 | "hooks": {
136 | "pre-commit": "lint-staged"
137 | }
138 | },
139 | "lint-staged": {
140 | "*.{ts,js,tsx,jsx}": [
141 | "eslint --fix",
142 | "prettier --write"
143 | ],
144 | "*.json": [
145 | "prettier --write"
146 | ]
147 | },
148 | ...
149 | }
150 | ```
151 |
152 | Now, everytime someone is `git commit`ing, `lint-staged` will guarantee that every staged file is following VTEX's standards.
153 |
154 | > _Note: if for some reason you need to commit files that doesn't follow the standards, you can pass the [`--no-verify`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-verify) flag to the `git commit` command. We trust you know what you're doing._
155 |
156 | ## CI Automation
157 |
158 | > Work in progress
159 |
--------------------------------------------------------------------------------
/fixtures/app/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | !.eslintrc.js
3 |
--------------------------------------------------------------------------------
/fixtures/app/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | extends: 'vtex-react',
4 | reportUnusedDisableDirectives: true,
5 | }
6 |
--------------------------------------------------------------------------------
/fixtures/app/.gitignore:
--------------------------------------------------------------------------------
1 | yarn.lock
2 |
--------------------------------------------------------------------------------
/fixtures/app/.prettierrc:
--------------------------------------------------------------------------------
1 | "@vtex/prettier-config"
2 |
--------------------------------------------------------------------------------
/fixtures/app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "app",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "scripts": {
7 | "test": "eslint --ext js,ts,jsx,tsx,mjs ."
8 | },
9 | "devDependencies": {
10 | "@vtex/prettier-config": "*",
11 | "eslint": "^7",
12 | "eslint-config-vtex": "*",
13 | "eslint-config-vtex-react": "*",
14 | "prettier": "^2.5.1",
15 | "typescript": "^4.6.2"
16 | },
17 | "dependencies": {
18 | "react": "^17.0.2",
19 | "react-dom": "^17.0.2"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "independent",
3 | "npmClient": "yarn",
4 | "useWorkspaces": true,
5 | "stream": true,
6 | "packages": ["packages/*"],
7 | "command": {
8 | "publish": {
9 | "ignoreChanges": [
10 | "{.*,*}{.config,rc,ignore}{,.js}",
11 | "LICENSE",
12 | "lerna.json"
13 | ],
14 | "message": "chore(release): :robot: publish",
15 | "registry": "https://registry.npmjs.org"
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@vtex/typescript",
3 | "private": true,
4 | "workspaces": [
5 | "packages/*"
6 | ],
7 | "contributors": [
8 | "Breno Calazans ",
9 | "Christian Kaisermann "
10 | ],
11 | "license": "MIT",
12 | "repository": "vtex/typescript",
13 | "bugs": {
14 | "url": "https://github.com/vtex/typescript/issues"
15 | },
16 | "scripts": {
17 | "build": "lerna run build",
18 | "clean": "lerna clean && lerna run clean",
19 | "format:check": "prettier --list-different \"./**/*.{ts,js,json}\"",
20 | "format": "prettier --write \"**/*.{ts,js,json}\"",
21 | "lint": "eslint --ext .js,.ts,.jsx,.tsx .",
22 | "test": "lerna run test --concurrency 1",
23 | "prepare": "husky install"
24 | },
25 | "prettier": "@vtex/prettier-config",
26 | "lint-staged": {
27 | "*.{ts,js}": [
28 | "eslint --fix",
29 | "prettier --write"
30 | ],
31 | "*.json": [
32 | "prettier --write"
33 | ]
34 | },
35 | "devDependencies": {
36 | "@geut/chan": "^2.1.1",
37 | "eslint": "^8.11.0",
38 | "husky": "^7.0.0",
39 | "lerna": "^3.18.4",
40 | "lint-staged": "^12.3.5",
41 | "prettier": "^2.2.0",
42 | "typescript": "^4.6.2"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["./index.js"]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [Unreleased]
8 |
9 | ## [9.0.3] - 2022-10-28
10 | ### Removed
11 | - Deprecated eslint plugin and preset for VTEX Admin UI
12 |
13 | ## [9.0.0] - 2022-03-15
14 | ### Changed
15 | - Include `eslint` major 8 in peer dependencies range.
16 |
17 | ## [8.0.0] - 2021-03-25
18 | ### Changed
19 | - `eslint-config-prettier` updated 6.15.0 to 8.1.0
20 | - Requires at least ESLint 7.0.0 now, because `eslint-config-prettier` drops support for ESLint 6, [see here](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-700-2020-12-05)
21 |
22 | ## [6.9.4] - 2021-01-29
23 | ### Changed
24 | - Update typescript-eslint dependencies
25 |
26 | ## 6.9.1 - 2020-12-09
27 | ### Fixed
28 | - Wrong preset extension.
29 |
30 | ## 6.9.0 - 2020-12-09
31 | ### Changed
32 | - Move hooks config to `react-hooks` file.
33 |
34 | ## 6.8.6 - 2020-12-03
35 | ### Fixed
36 | - Add `env.browser: true` to react preset.
37 |
38 | ## 6.8.4 - 2020-11-25
39 | ### Added
40 | - `useCustomClasses` hook to `react-hooks/exhaustive-deps` rule to io.
41 |
42 | ## 6.8.2 - 2020-11-19
43 | ### Added
44 | - Ignore jsx-filename rule for `gatsby-browser.js`.
45 |
46 | ## 6.8.1 - 2020-11-19
47 | ### Fixed
48 | - Missing entrypoing for gatsby preset.
49 |
50 | ## 6.8.0 - 2020-11-19
51 | ### Added
52 | - `vtex-react/gatsby` preset.
53 |
54 | ## 6.7.12 - 2020-11-18
55 | ### Changed
56 | - Allow components to have all capitalized names.
57 |
58 | ## 6.7.9 - 2020-10-21
59 | ### Changed
60 | - Repo url in package.json
61 |
62 | ## 6.7.7 - 2020-08-21
63 | ### Changed
64 | - Update hooks preset to v4
65 |
66 | ## 6.7.1 - 2020-07-20
67 | ### Changed
68 | - Message from imports of `ramda` and `lodash`.
69 |
70 | ## 6.5.0 - 2020-06-01
71 | ### Added
72 | - `prettier` `v2.0` as acceptable dependency.
73 |
74 | ## 6.3.1 - 2020-03-30
75 | ### Fixed
76 | - Release cycle.
77 |
78 | ## 6.2.2 - 2020-03-30
79 | ### Fixed
80 | - Allow to use ramda/lodash and node libraries in a testing context.
81 |
82 | ## [6.2.1] - 2020-02-28
83 | ### Fixed
84 | - Add sub presets to package bundle
85 |
86 | ## [6.2.0] - 2020-02-28
87 | ### Added
88 | - Add IO and Native presets
89 |
90 | ## [6.1.1] - 2020-02-14
91 | ### Fixed
92 | - Use explicitly latest react version
93 |
94 | ## [6.0.3] - 2020-01-24
95 | ### Fixed
96 | - Changelog on deploy workflow again.
97 |
98 | ## [6.0.2] - 2020-01-24
99 | ### Fixed
100 | - Changelog on deploy workflow.
101 |
102 | ## [6.0.1] - 2020-01-24
103 | ### Fixed
104 | - Missing files in packages.
105 |
106 | ## 6.0.0 - 2020-01-24
107 | ### Changed
108 | - Whole project structure.
109 |
110 | ### Added
111 | - New rules to ensure best practices.
112 | - New rules to enforce a default coding style.
113 |
114 | ## 5.1.0 - 2019-10-31
115 | ### Added
116 | - Rule to warn when a native node package is imported.
117 |
118 | ## 5.0.1 - 2019-07-25
119 | ### Changed
120 | - Updated `eslint-plugin-react` version.a
121 |
122 | ## 5.0.0 - 2019-07-15
123 | ### Changed
124 | - Updated `eslint-config-vtex` dependency version.
125 |
126 | ## 4.1.0 - 2019-04-29
127 | ### Fixed
128 | - Disabled all rules conflicting with `eslint-config-prettier/react`.
129 |
130 | ## 4.0.0 - 2019-03-15
131 | ### Changed
132 | - Add support for typescript by extending `eslint-config-vtex` v10.
133 | - Add more rules for a11y in components.
134 |
135 | [Unreleased]: https://github.com/vtex/typescript/compare/v9.0.3...HEAD
136 | [9.0.3]: https://github.com/vtex/typescript/compare/v9.0.0...v9.0.3
137 | [9.0.0]: https://github.com/vtex/typescript/compare/v8.0.0...v9.0.0
138 | [8.0.0]: https://github.com/vtex/typescript/compare/v6.9.4...v8.0.0
139 | [6.9.4]: https://github.com/vtex/typescript/compare/v6.9.1...v6.9.4
140 | [6.2.1]: https://github.com/vtex/javascript/compare/v6.2.0...v6.2.1
141 | [6.2.0]: https://github.com/vtex/javascript/compare/v6.1.1...v6.2.0
142 | [6.1.1]: https://github.com/vtex/javascript/compare/v6.0.3...v6.1.1
143 | [6.0.3]: https://github.com/vtex/js-standards/compare/v6.0.2...v6.0.3
144 | [6.0.2]: https://github.com/vtex/js-standards/compare/v6.0.1...v6.0.2
145 | [6.0.1]: https://github.com/vtex/js-standards/compare/v6.0.0...v6.0.1
146 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/README.md:
--------------------------------------------------------------------------------
1 | # `eslint-config-vtex-react`
2 |
3 | This package provides VTEX's `.eslintrc` for React projects as an extensible shared config.
4 |
5 | Not all React applications live in the same context, different rules are needed for different scenarios. To solve this, three presets are provided:
6 |
7 | - `vtex-react` - Base react configuration. Can be used in any React project.
8 | - `vtex-react/io` - To be used in VTEX IO React applications.
9 | - `vtex-react/native` - To be used in `react-native` applications.
10 |
11 | ## Installation
12 |
13 | Assuming you already have ESLint installed, run:
14 |
15 | ```bash
16 | yarn add -D eslint-config-vtex-react typescript prettier
17 | ```
18 |
19 | ## Usage
20 |
21 | After installing the module, just add it to your `extends` array inside your `.eslintrc`.
22 |
23 | ```jsonc
24 | // .eslintrc
25 | {
26 | "extends": ["vtex-react"]
27 | }
28 | ```
29 |
30 | As any other eslint preset, it's possible to override some rules and configurations. We encourage trying to keep the closest possible to the preset rules, but every project is different and sometimes overriding is needed, use it carefully.
31 |
32 | ## References
33 |
34 | - [`eslint-config-vtex` documentation](https://github.com/vtex/javascript/blob/master/packages/eslint-config-vtex/README.md)
35 | - [`eslint-plugin-jsx-a11y` documentation](https://github.com/evcohen/eslint-plugin-jsx-a11y#readme)
36 | - [`eslint-plugin-react` documentation](https://github.com/yannickcr/eslint-plugin-react)
37 | - [`eslint-plugin-react-hooks` documentation](https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks)
38 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/demo/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../index.js"
3 | }
4 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/demo/Component.tsx:
--------------------------------------------------------------------------------
1 | import type { FC } from 'react'
2 | import React from 'react'
3 |
4 | const AnotherComponent: FC = () => {
5 | return null
6 | }
7 |
8 | const Component: FC = () => {
9 | return (
10 |
14 | )
15 | }
16 |
17 | export default Component
18 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "main": "index.js",
4 | "license": "MIT",
5 | "devDependencies": {
6 | "@types/react": "^17.0.0"
7 | },
8 | "dependencies": {
9 | "react": "^17.0.1"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/gatsby.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['./index.js'],
3 | overrides: [
4 | // gatsby config files
5 | {
6 | files: ['gatsby-{ssr,browser,node,config}.{js,jsx,ts,tsx}'],
7 | rules: {
8 | 'global-require': 'off',
9 | '@typescript-eslint/no-require-imports': 'off',
10 | '@typescript-eslint/no-var-requires': 'off',
11 | },
12 | },
13 | // allowed to use node libs
14 | {
15 | files: ['gatsby-{node,config,ssr}.{js,jsx,ts,tsx}'],
16 | rules: {
17 | 'import/no-nodejs-modules': 'off',
18 | },
19 | },
20 | // needs to be .js/.js
21 | {
22 | files: ['gatsby-browser.{js,ts}'],
23 | rules: {
24 | 'react/jsx-filename-extension': 'off',
25 | },
26 | },
27 | ],
28 | }
29 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/index.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: [
3 | 'eslint-config-vtex',
4 | './rules/react.js',
5 | './rules/react-hooks.js',
6 | './rules/react-a11y.js',
7 | ],
8 | overrides: [
9 | {
10 | files: '**/*.{ts,tsx,js,jsx}',
11 | excludedFiles: ['*{_,.}{test,spec}.{ts,tsx,js,jsx}', '__tests__/**/*'],
12 | // activate these rules in react files not related to testing
13 | rules: {
14 | // prevent people from importing native Node libs (url/path/crypto, etc) on browser env
15 | 'import/no-nodejs-modules': 'error',
16 | },
17 | },
18 | ],
19 | }
20 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/io.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['./index.js'],
3 | overrides: [
4 | {
5 | files: '**/*.{ts,tsx,js,jsx}',
6 | excludedFiles: ['*{_,.}{test,spec}.{ts,tsx,js,jsx}', '__tests__/**/*'],
7 | // activate these rules in react files not related to testing
8 | rules: {
9 | // Disallow specified import patterns
10 | // https://eslint.org/docs/rules/no-restricted-imports
11 | 'no-restricted-imports': [
12 | 'error',
13 | {
14 | paths: [
15 | {
16 | name: 'lodash',
17 | message:
18 | 'You might not need lodash, try using the default functions from the browser',
19 | },
20 | {
21 | name: 'ramda',
22 | message:
23 | 'You might not need ramda, try using the default functions from the browser',
24 | },
25 | ],
26 | // Patterns don't support messages yet :(
27 | // https://github.com/eslint/eslint/issues/11843
28 | patterns: [],
29 | },
30 | ],
31 |
32 | // Add useCustomClasses hook from vtex-apps/css-handles
33 | // https://eslint.org/docs/rules/no-restricted-imports
34 | 'react-hooks/exhaustive-deps': [
35 | 'warn',
36 | {
37 | // regexp
38 | additionalHooks: '(useCustomClasses)',
39 | },
40 | ],
41 | },
42 | },
43 | ],
44 | }
45 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/native.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['./index.js'],
3 | }
4 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eslint-config-vtex-react",
3 | "version": "9.1.0",
4 | "description": "VTEX's eslint config for React",
5 | "main": "index.js",
6 | "scripts": {
7 | "eslint-check": "eslint-config-prettier index.js",
8 | "dump-config": "eslint-config-prettier index.js > config-dump.json",
9 | "version": "chan release $npm_package_version && git add CHANGELOG.md"
10 | },
11 | "files": [
12 | "index.js",
13 | "io.js",
14 | "native.js",
15 | "gatsby.js",
16 | "rules/"
17 | ],
18 | "keywords": [
19 | "eslint",
20 | "config",
21 | "vtex",
22 | "react"
23 | ],
24 | "contributors": [
25 | "Breno Calazans ",
26 | "Christian Kaisermann "
27 | ],
28 | "license": "MIT",
29 | "bugs": {
30 | "url": "https://github.com/vtex/javascript/issues"
31 | },
32 | "homepage": "https://github.com/vtex/typescript",
33 | "repository": {
34 | "type": "git",
35 | "url": "https://github.com/vtex/typescript.git",
36 | "directory": "packages/eslint-config-vtex-react"
37 | },
38 | "dependencies": {
39 | "eslint-config-vtex": "^15.1.0",
40 | "eslint-plugin-jsx-a11y": "^6.3.1",
41 | "eslint-plugin-react": "^7.20.6",
42 | "eslint-plugin-react-hooks": "^4.1.0"
43 | },
44 | "peerDependencies": {
45 | "eslint": "^7 || ^8",
46 | "prettier": "^1.18.2 || ^2.0.4",
47 | "typescript": "^3.8 || ^4.0.0"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/packages/eslint-config-vtex-react/rules/react-a11y.js:
--------------------------------------------------------------------------------
1 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/
2 | module.exports = {
3 | extends: ['plugin:jsx-a11y/recommended'],
4 | plugins: ['jsx-a11y'],
5 | parserOptions: {
6 | ecmaFeatures: {
7 | jsx: true,
8 | },
9 | },
10 | rules: {
11 | // Enforce that anchors have content
12 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
13 | 'jsx-a11y/anchor-has-content': 'error',
14 |
15 | // Require ARIA roles to be valid and non-abstract
16 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md
17 | 'jsx-a11y/aria-role': 'error',
18 |
19 | // Enforce all aria-* props are valid.
20 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-props.md
21 | 'jsx-a11y/aria-props': 'error',
22 |
23 | // Enforce ARIA state and property values are valid.
24 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-proptypes.md
25 | 'jsx-a11y/aria-proptypes': 'error',
26 |
27 | // Enforce that elements that do not support ARIA roles, states, and
28 | // properties do not have those attributes.
29 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-unsupported-elements.md
30 | 'jsx-a11y/aria-unsupported-elements': 'error',
31 |
32 | // Enforce that all elements that require alternative text have meaningful information
33 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md
34 | 'jsx-a11y/alt-text': 'error',
35 |
36 | // Prevent img alt text from containing redundant words like "image", "picture", or "photo"
37 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md
38 | 'jsx-a11y/img-redundant-alt': 'error',
39 |
40 | // Require that JSX labels use "htmlFor"
41 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
42 | // deprecated: replaced by `label-has-associated-control` rule
43 | 'jsx-a11y/label-has-for': 'off',
44 |
45 | // Enforce that a label tag has a text label and an associated control.
46 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/b800f40a2a69ad48015ae9226fbe879f946757ed/docs/rules/label-has-associated-control.md
47 | 'jsx-a11y/label-has-associated-control': [
48 | 'error',
49 | {
50 | labelComponents: [],
51 | labelAttributes: [],
52 | controlComponents: ['Input'],
53 | },
54 | ],
55 |
56 | // Enforce that a control (an interactive element) has a text label.
57 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/control-has-associated-label.md
58 | 'jsx-a11y/control-has-associated-label': [
59 | 'off',
60 | {
61 | ignoreElements: [
62 | 'audio',
63 | 'canvas',
64 | 'embed',
65 | 'input',
66 | 'textarea',
67 | 'tr',
68 | 'video',
69 | ],
70 | ignoreRoles: [
71 | 'grid',
72 | 'listbox',
73 | 'menu',
74 | 'menubar',
75 | 'radiogroup',
76 | 'row',
77 | 'tablist',
78 | 'toolbar',
79 | 'tree',
80 | 'treegrid',
81 | ],
82 | includeRoles: ['alert', 'dialog'],
83 | },
84 | ],
85 |
86 | // Require that mouseover/out come with focus/blur, for keyboard-only users
87 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md
88 | 'jsx-a11y/mouse-events-have-key-events': 'error',
89 |
90 | // Prevent use of `accessKey`
91 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md
92 | 'jsx-a11y/no-access-key': 'error',
93 |
94 | // Require onBlur instead of onChange
95 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md
96 | 'jsx-a11y/no-onchange': 'off',
97 |
98 | // Elements with an interactive role and interaction handlers must be focusable
99 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/interactive-supports-focus.md
100 | 'jsx-a11y/interactive-supports-focus': [
101 | 'error',
102 | {
103 | tabbable: [
104 | 'button',
105 | 'checkbox',
106 | 'link',
107 | 'searchbox',
108 | 'spinbutton',
109 | 'switch',
110 | 'textbox',
111 | ],
112 | },
113 | ],
114 |
115 | // Enforce that elements with ARIA roles must have all required attributes
116 | // for that role.
117 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-has-required-aria-props.md
118 | 'jsx-a11y/role-has-required-aria-props': 'error',
119 |
120 | // Enforce that elements with explicit or implicit roles defined contain
121 | // Only aria-* properties supported by that role.
122 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-supports-aria-props.md
123 | 'jsx-a11y/role-supports-aria-props': 'error',
124 |
125 | // Enforce tabIndex value is not greater than zero.
126 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md
127 | 'jsx-a11y/tabindex-no-positive': 'error',
128 |
129 | // ensure tags have content and are not aria-hidden
130 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/heading-has-content.md
131 | 'jsx-a11y/heading-has-content': 'error',
132 |
133 | // Require HTML elements to have a "lang" prop
134 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/html-has-lang.md
135 | 'jsx-a11y/html-has-lang': 'error',
136 |
137 | // Require HTML element's lang prop to be valid
138 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/lang.md
139 | 'jsx-a11y/lang': 'error',
140 |
141 | // prevent distracting elements, like