Skip to content

Commit

Permalink
Merge pull request #60 from microsoft/dev/martinkamar/eslint-v9
Browse files Browse the repository at this point in the history
ESLint v9 support
  • Loading branch information
mkacmar authored Sep 30, 2024
2 parents 3a9984f + 389ab98 commit d435fec
Show file tree
Hide file tree
Showing 30 changed files with 3,949 additions and 417 deletions.
88 changes: 0 additions & 88 deletions .github/workflows/E2E integration.yml

This file was deleted.

89 changes: 89 additions & 0 deletions .github/workflows/e2e-integration.yml
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
7 changes: 3 additions & 4 deletions .github/workflows/node-version-integration.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

name: Node CI
name: Node.js integration

on:
push:
Expand All @@ -17,14 +17,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm run build --if-present
- run: npm install
- run: npm test
4 changes: 0 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ on:
types: [created]

jobs:
# Run one last check
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
- run: npm i
- run: npm test

Expand All @@ -26,7 +23,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm publish
Expand Down
56 changes: 29 additions & 27 deletions README.md
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)

Expand All @@ -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.

Expand Down Expand Up @@ -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.
21 changes: 11 additions & 10 deletions config/angular.js
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"
}
}
}
];
};
29 changes: 15 additions & 14 deletions config/angularjs.js
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"
}
}
];
};
Loading

0 comments on commit d435fec

Please sign in to comment.