@aptos-scp/eslint-config-scp
v1.1.17
Published
A component containing the default eslint rule configuration for Singular Commerce projects.
Downloads
4,446
Maintainers
Readme
@aptos-scp/eslint-config-scp
A component containing the default ESLint rule configuration for Aptos ONE projects.
Peer dependencies
"peerDependencies": {
"eslint": ">= 8",
"typescript": ">= 3.5"
}Formatting code
Most popular IDEs such as VSCode and WebStorm support automatic prettier code formatting in the IDE experience.
VSCode Prettier plugin
The following plugin can be used to automatically format code when saved or modified: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
WebStore Prettier formatting
Prettier formatting is supported by WebStorm and can be configured within the IDE.
Installation on a new repository
1. Install new packages
npm install --save-dev @aptos-scp/eslint-config-scp eslint2. Create eslint configuration file
You will need to add an .eslintrc.json file which can simply be:
.eslintrc.json
{
"extends": "@aptos-scp/eslint-config-scp"
}3. Lint script in package.json
Add a lint script to package.json similar to the following:
"lint": "eslint --ext .ts \"@(src|test)/**/*.ts?(x)\""Note: Make sure you are pointing to the appropriate source folder /src or /lib and include all the necessary file extensions.
Upgrading a repository from @aptos-scp/scp-tslint-recommended
1. Install new packages
npm install --save-dev @aptos-scp/eslint-config-scp eslint2. Uninstall scp-tslint-recommended and delete config file
npm uninstall @aptos-scp/scp-tslint-recommended tslint
rm tslint.json3. Create eslint configuration file
You will need to add an .eslintrc.json file which can simply be:
.eslintrc.json
{
"extends": "@aptos-scp/eslint-config-scp"
}If using the default configuration referenced above produces a large number of errors and warnings, then the following transitional configuration may be used temporarily to relax the enforcement of some rules in order to complete the migration to ESLint as quickly as possible. Resolution of the remaining errors and warnings and a final migration to the default configuration should be tracked as technical debt and scheduled accordingly.
.eslintrc.json
{
"extends": "@aptos-scp/eslint-config-scp/transition-config"
}4. Modify lint script in package.json
When switching from scp-tslint-recommended to eslint-config-scp you will need to be modify existing lint script in package.json, you will likely find something similar to:
"lint": "tslint --project tsconfig-lint.json -c tslint.json"Which you will want to switch to eslint with something similar to:
"lint": "eslint --ext .ts \"@(src|test)/**/*.ts?(x)\""Note: Make sure you are pointing to the appropriate source folder /src or /lib and include all the necessary file extensions.
Additional Information
ESLint (https://eslint.org)
ESLint is a highly customizable static code analysis tool, allowing for configuring and disabling of linter rules. Detailed instructions for configuring ESlint can be found here.
Aptos ONE repositories which were transitioned from '@aptos-scp/scp-tslint-recommended' to ESLint have typically had various linter rules excluded as required to successfully build. Resolution of the remaining errors and warnings and a final migration to the default configuration should be tracked as technical debt and scheduled accordingly.
Prettier (https://prettier.io)
Prettier is an opinionated code formatter.
How to use prettier to format code:
We recommend you use options 1 or 2 when you want to format a project for the first time and option 3 to automatically format any new changes as you are working.
Option 1: Use prettier cli
Prettier can be executed directly from the command line using the following command to modify all relevant files in the local directory, taking into account any current configuration settings specified in .prettierrc and .prettierignore files in the path.
prettier --write .The following command would modify all typescript files:
prettier 'src/**/*.ts' --writeMultiple extensions are supported:
"./src/**/*.{ts,tsx}"Multiple directories are also supported:
prettier --write "src/**/*.{ts,tsx,js,jsx}" "test/**/*.{ts,tsx,js,jsx}"Note: Make sure you are pointing to the appropriate source folder /src or /lib and include all the necessary file extensions.
Option 2: eslint with fix parameter
ESLint can also be used in "fix" mode to execute prettier formatting because prettier is configured as a plugin for eslint.
eslint -c .eslintrc.js --ext .ts \"@(src|test)/**/*.ts?(x)\" --fixOption 3: VSCode Prettier plugin
The following plugin can be used to automatically format code when saved or modified: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
License
Please see LICENSE.md.
