Skip to content

Latest commit

 

History

History
117 lines (78 loc) · 2.6 KB

STATIC_CODE_ANALYSIS.md

File metadata and controls

117 lines (78 loc) · 2.6 KB

Static Code Analysis

Linting

We use ESLint as the primary linting tool, and it's important that you adhere to the defined ruleset in the configuration.

Set up the ESLint plugin corresponding to the IDE/Code editor you are using. For more information, follow the instructions here.

Always keep an eye out for the inline warnings and errors given out by the plugin.

Running the linter

Execute the following commands based on the requirement to analyze the code with ESLint.

For the Entire Mono-repo

# Run this from the root.
npm run lint

For a specific module/app.

Example: To run linter on Console
cd apps/console
npm run lint

or

# From anywhere in the project.
npx lerna run lint --scope @wso2is/console --stream
Example: To run linter on React Components
cd modules/react-components
npm run lint

or

# From anywhere in the project.
npx lerna run lint --scope @wso2is/react-components --stream

For a specific folder or a file.

The script lint:targeted is meant to be used if you need to run the linter on a specific folder or file inside an app or a module.

Example: To run linter on features/applications inside the Console
cd apps/console
npm run lint:targeted -- src/features/applications
Example: To run linter on basic-application.spec.ts test file inside the integration test suite.
cd tests
npm run lint:targeted -- integration/applications/basic-application.spec.ts

Auto-fixing Issues

ESLint has the ability to auto-fix certain warnings and errors.

This can be done using the CLI as well as via the IDE/Code Editor using the integrated ESLint Plugin.

Execute the following commands to auto-fix possible issues using the CLI.

Auto-fix issues in the entire Mono-repo

# Run this from the root.
npm run lint:autofix

Auto-fix issues in a specific module/app.

Example: To fix issues in Core module
cd modules/core
npm run lint:autofix

or

# From anywhere in the project.
npx lerna run lint:autofix --scope @wso2is/core --stream

Auto-fix issues in a specific folder or a file.

Example: To fix issues in api directory inside the My Account
cd apps/myaccount
npm run lint:targeted -- src/api --fix
Example: To fix issues in url-utils.ts file inside the Core module.
cd modules/core
npm run lint:targeted -- src/utils/url-utils.ts --fix