-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from microsoft/dev/martinkamar/eslint-v9
ESLint v9 support
- Loading branch information
Showing
30 changed files
with
3,949 additions
and
417 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,89 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
name: E2E integration | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request_target: | ||
branches: [main] | ||
|
||
env: | ||
GITHUB_REPO: nodejs/node | ||
GITHUB_REPO_ESLINT_GLOB: lib | ||
GITHUB_REPO_TSCONFIG: tsconfig.json | ||
TEST_TARGET_DIR: test-target | ||
TEST_RUN_DIR: test-run | ||
PLUGIN_DIR: eslint-plugin-sdl | ||
|
||
# This job runs the plugin with latest ESLint on the target repository in GITHUB_REPO env variable. | ||
jobs: | ||
build: | ||
name: E2E run with SARIF | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
|
||
steps: | ||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
|
||
- name: Create test run directory | ||
run: mkdir ${{env.TEST_RUN_DIR}} | ||
|
||
- name: Install ESLint and dependencies required for test | ||
run: | | ||
npm i eslint | ||
npm i typescript | ||
npm i @microsoft/eslint-formatter-sarif | ||
working-directory: ${{env.TEST_RUN_DIR}} | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{env.GITHUB_REPO}} | ||
path: ${{env.TEST_RUN_DIR}}/${{env.TEST_TARGET_DIR}} | ||
clean: true | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
path: ${{env.PLUGIN_DIR}} | ||
clean: true | ||
|
||
- name: Install plugin dependencies | ||
run: npm install --production | ||
working-directory: ${{env.PLUGIN_DIR}} | ||
|
||
- name: Link plugin | ||
run: sudo npm link ../${{env.PLUGIN_DIR}} | ||
working-directory: ${{env.TEST_RUN_DIR}} | ||
if: runner.os == 'Linux' | ||
|
||
- name: Link plugin | ||
run: npm link ../${{env.PLUGIN_DIR}} | ||
working-directory: ${{env.TEST_RUN_DIR}} | ||
if: runner.os == 'Windows' | ||
|
||
- name: Create ESLint config file | ||
run: echo 'module.exports = [...require("@microsoft/eslint-plugin-sdl").configs.recommended];' > eslint.config.js | ||
working-directory: ${{env.TEST_RUN_DIR}} | ||
|
||
- name: Run ESLint | ||
run: npx eslint | ||
--config eslint.config.js | ||
--no-config-lookup | ||
${{env.TEST_TARGET_DIR}}/${{env.GITHUB_REPO_ESLINT_GLOB}} | ||
--parser-options=project:${{env.TEST_TARGET_DIR}}/${{env.GITHUB_REPO_TSCONFIG}} | ||
--format @microsoft/eslint-formatter-sarif | ||
--output-file eslint-result-${{ matrix.os }}-${{github.run_id}}.sarif | ||
working-directory: ${{env.TEST_RUN_DIR}} | ||
continue-on-error: true | ||
|
||
- name: Upload ESLint results as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: eslint-result-${{ matrix.os }} | ||
path: ${{env.TEST_RUN_DIR}}/eslint-result-${{ matrix.os }}-${{github.run_id}}.sarif | ||
if-no-files-found: error |
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
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,4 +1,5 @@ | ||
# eslint-plugin-sdl | ||
|
||
![Node CI](https://github.com/microsoft/eslint-plugin-sdl/workflows/Node%20CI/badge.svg?branch=main&event=push) | ||
![E2E integration](https://github.com/microsoft/eslint-plugin-sdl/workflows/E2E%20integration/badge.svg?branch=main&event=push) | ||
|
||
|
@@ -16,50 +17,51 @@ or | |
yarn add microsoft/eslint-plugin-sdl | ||
``` | ||
|
||
## Usage | ||
When you run npm install within your project's root folder, the plugin will be added automatically to your package.json and package-lock.json files. You can also add the plugin to your package.json file manually by specifying the name and version number in the dependencies section like so: | ||
## Configs | ||
|
||
```sh | ||
"dependencies": { | ||
"@microsoft/eslint-plugin-sdl": "^0.2.2" | ||
} | ||
``` | ||
Including an ESLint configuration file in your project allows you to customize how ESLint applies rules to your project. You can include the plugin in your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files) by adding: | ||
|
||
Run npm install within your root folder to install everything listed in the dependencies section of package.json. If the plugin is listed in your package.json dependencies, eslint will enforce all plugin rules using default settings. | ||
```js | ||
const pluginMicrosoftSdl = require("@microsoft/eslint-plugin-sdl"); | ||
|
||
## Configs | ||
Including an eslint configuration file in your project allows you to customize how eslint applies rules to your project. If you are using an .eslintrc file, you can include the plugin by adding: | ||
|
||
```sh | ||
plugins: ["@microsoft/eslint-plugin-sdl"] | ||
module.exports = [ | ||
...pluginMicrosoftSdl.configs.recommended | ||
]; | ||
``` | ||
|
||
Eslint will then only enforce rules you specify in the rules section of your .eslintrc file at the severity level you designate. The severity level options are 0 (no error), 1 (warning), and 2 (error). For example: | ||
ESLint will then only enforce rules you specify in the rules section of your configuration file at the [severity level](https://eslint.org/docs/latest/use/configure/rules) you designate. For example: | ||
|
||
```sh | ||
rules: { | ||
"no-eval": 2, | ||
"@microsoft/sdl/no-inner-html": 2 | ||
} | ||
```js | ||
const pluginMicrosoftSdl = require("@microsoft/eslint-plugin-sdl"); | ||
|
||
module.exports = [ | ||
...pluginMicrosoftSdl.configs.recommended, | ||
{ | ||
rules: { | ||
"no-eval": "error", | ||
"@microsoft/sdl/no-inner-html": "error" | ||
} | ||
} | ||
]; | ||
``` | ||
|
||
You can also used the below Shareable config files as guidelines depending on the type of project. | ||
You can also used the below Shareable Config files using flat config model as guidelines depending on the type of project. | ||
|
||
Plugin is shipped with following [Shareable Configs](http://eslint.org/docs/developer-guide/shareable-configs): | ||
|
||
- [angular](config/angular.js) - Set of rules for [Angular](https://angular.io) applications | ||
- [angularjs](config/angularjs.js) - Set of rules for [AngularJS](https://docs.angularjs.org) applications | ||
- [angular](config/angular.js) - Set of rules for modern [Angular](https://angular.io) applications | ||
- [angularjs](config/angularjs.js) - Set of rules for legacy [AngularJS](https://docs.angularjs.org) applications | ||
- [common](config/common.js) - Set of rules for common JavaScript applications | ||
- [electron](config/electron.js) - Set of rules for Electron applications | ||
- [node](config/node.js) - Set of rules for Node applications | ||
- [node](config/node.js) - Set of rules for Node.js applications | ||
- [react](config/react.js) - Set of rules for [ReactJS](https://reactjs.org) applications | ||
- [**recommended**](config/recommended.js) - SDL Recommended rules for all applications | ||
- [**required**](config/required.js) - SDL Required rules for all applications | ||
- [**recommended**](lib/index.js) - SDL Recommended rules for all applications | ||
- [**required**](lib/index.js) - SDL Required rules for all applications | ||
- [typescript](config/typescript.js) - Set of rules for TypeScript applications | ||
|
||
## Rules | ||
|
||
Where possible, we leverage existing rules from [ESLint](https://eslint.org/docs/rules/) and community plugins such as [react](https://github.com/yannickcr/eslint-plugin-react), [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules) or [security](https://github.com/nodesecurity/eslint-plugin-security#rules). | ||
Where possible, we leverage existing rules from [ESLint](https://eslint.org/docs/rules/) and community plugins such as [react](https://github.com/jsx-eslint/eslint-plugin-react), [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin#supported-rules) or [security](https://github.com/nodesecurity/eslint-plugin-security#rules). | ||
|
||
We also implemented several [custom rules](./lib/rules) where we did not find sufficient alternative in the community. | ||
|
||
|
@@ -102,4 +104,4 @@ provided by the bot. You will only need to do this once across all repos using o | |
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
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,17 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Shareable config for Angular apps. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
module.exports = { | ||
plugins: [ | ||
"@microsoft/sdl" | ||
], | ||
rules: { | ||
// Generates shareable config for modern Angular (https://angular.dev/) apps. | ||
module.exports = (pluginSdl) => { | ||
return [ | ||
{ | ||
plugins: { | ||
"@microsoft/sdl": pluginSdl | ||
}, | ||
rules: { | ||
"@microsoft/sdl/no-angular-bypass-sanitizer": "error" | ||
} | ||
} | ||
} | ||
]; | ||
}; |
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,19 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Shareable config for AngularJS apps. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
module.exports = { | ||
plugins: [ | ||
"@microsoft/sdl" | ||
], | ||
rules: { | ||
"@microsoft/sdl/no-angularjs-enable-svg": "error", | ||
"@microsoft/sdl/no-angularjs-sanitization-whitelist": "error", | ||
"@microsoft/sdl/no-angularjs-bypass-sce": "error" | ||
} | ||
} | ||
// Generates shareable config for legacy AngularJS (https://angularjs.org/) apps. | ||
module.exports = (pluginSdl) => { | ||
return [ | ||
{ | ||
plugins: { | ||
"@microsoft/sdl": pluginSdl | ||
}, | ||
rules: { | ||
"@microsoft/sdl/no-angularjs-enable-svg": "error", | ||
"@microsoft/sdl/no-angularjs-sanitization-whitelist": "error", | ||
"@microsoft/sdl/no-angularjs-bypass-sce": "error" | ||
} | ||
} | ||
]; | ||
}; |
Oops, something went wrong.