Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to typescript-eslint v6 #118

Merged
merged 10 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-pr-reviews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Check PR Reviews
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- name: Perform Check of PR Reviews
uses: checkdigit/github-actions/check-pr-reviews@main
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/check-published-scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Published

on:
workflow_dispatch:
schedule:
- cron: '14 18 * * *'

jobs:
checkPublished:
runs-on: ubuntu-latest
name: Check Published
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- name: Check Published
uses: checkdigit/github-actions/check-published@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
DEBUG: '*'
SLACK_PUBLISH_MISMATCH: ${{ secrets.SLACK_PUBLISH_MISMATCH }}
19 changes: 8 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
branches:
- 'main'

env:
CI: true

jobs:
pullRequestBuild:
name: Pull Request Build
Expand All @@ -22,14 +19,14 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Check Label
uses: checkdigit/github-actions/check-label@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Audit Signatures
run: npm audit signatures
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Compile
run: npm run ci:compile
- name: Check Code Style
Expand All @@ -54,14 +51,14 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Check Label
uses: checkdigit/github-actions/check-label@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Audit Signatures
run: npm audit signatures
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Compile
run: npm run ci:compile
- name: Check Code Style
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Publish Beta
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci --ignore-scripts
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.idea
build
build
coverage
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

134 changes: 58 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,33 @@
* }
*/

const eslintRulesWithError = {};

// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires,unicorn/prefer-module
const eslintStrictRules = require('@typescript-eslint/eslint-plugin').configs['strict'].rules;
for (const [key, value] of Object.entries(eslintStrictRules)) {
if (value === 'warn') {
eslintRulesWithError[key] = 'error';
}
}

// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires,unicorn/prefer-module
const eslintRecommendedRules = require('@typescript-eslint/eslint-plugin').configs['recommended'].rules;
for (const [key, value] of Object.entries(eslintRecommendedRules)) {
if (value === 'warn') {
eslintRulesWithError[key] = 'error';
}
}

// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires,unicorn/prefer-module
const eslintRecommendedRequiringTypeCheckingRules = require('@typescript-eslint/eslint-plugin').configs[
'recommended-requiring-type-checking'
].rules;
for (const [key, value] of Object.entries(eslintRecommendedRequiringTypeCheckingRules)) {
if (value === 'warn') {
eslintRulesWithError[key] = 'error';
}
}

// eslint-disable-next-line unicorn/prefer-module
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@checkdigit', '@typescript-eslint', 'sonarjs', 'import', 'no-only-tests', 'no-secrets', 'deprecate'],
plugins: ['@checkdigit', '@typescript-eslint', 'sonarjs', 'import', 'no-only-tests', 'no-secrets', 'n'],
Copy link
Contributor

@ramaghanta ramaghanta Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until I saw the node specific rules down below, I thought this n was a mistake

parserOptions: {
project: './tsconfig.json',
},
extends: [
'eslint:all',
'plugin:@checkdigit/all',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:import/errors',
'plugin:import/typescript',
'plugin:n/recommended',
'plugin:sonarjs/recommended',
'prettier',
'plugin:eslint-comments/recommended',
'plugin:unicorn/recommended',
'prettier',
],
settings: {
'import/resolver': {
typescript: true,
node: true,
},
},
rules: {
...eslintRulesWithError,
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': [
Expand All @@ -69,9 +48,6 @@ module.exports = {
},
],
'no-underscore-dangle': 'off',
'deprecate/function': 'error',
'deprecate/member-expression': 'error',
'deprecate/import': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': ['error'],
'func-names': 'off',
Expand All @@ -95,36 +71,9 @@ module.exports = {
// enforce use of curly braces around if statements and discourage one-line ifs
curly: 'error',

// always use ===
eqeqeq: 'error',

// undefined can be used
'no-undefined': 'off',

// tslint does this and it feels like a good idea
'guard-for-in': 'error',

// we should never use eval
'no-eval': 'error',
'no-implied-eval': 'error',

// disallow "this" outside of classes or class-like objects
'no-invalid-this': 'error',

// sync methods are slow and block the main event loop
'no-sync': 'error',

// modules we don't like
'no-restricted-modules': ['error', 'url'],

// prefer else-if
'no-lonely-if': 'error',

// make eslint feel just like the tslint days
'no-unneeded-ternary': 'error',
'one-var': ['error', 'never'],

// these two configurations need to be kept in sync
'sort-imports': [
'error',
{
Expand All @@ -138,16 +87,43 @@ module.exports = {
'newlines-between': 'ignore',
},
],

// turn on node-specific stylistic rules
'n/exports-style': 'error',
'n/no-restricted-import': ['error', ['moment', 'clone', 'fclone', 'lodash', 'underscore']],
'n/no-process-env': 'error',
'n/no-sync': 'error',
'n/prefer-global/buffer': 'error',
'n/prefer-global/console': 'error',
'n/prefer-global/process': 'error',
'n/prefer-global/text-decoder': 'error',
'n/prefer-global/text-encoder': 'error',
'n/prefer-global/url': 'error',
'n/prefer-global/url-search-params': 'error',

// this doesn't work for our style of imports
'n/no-missing-import': 'off',
'n/no-extraneous-import': 'off',

// this doesn't seem to work
'n/no-unpublished-import': 'off',

// duplicated by unicorn/no-process-exit
'n/no-process-exit': 'off',

// import-specific rules
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/*.spec.ts', '**/*.test.ts'],
optionalDependencies: false,
},
],
'import/no-deprecated': 'error',
'space-before-blocks': 'error',
'space-unary-ops': 'error',
'import/namespace': 'off',

// has a bug, throws an exception in some cases
'import/export': 'off',

'spaced-comment': 'error',
'no-var': 'error',
'prefer-const': 'error',
Expand All @@ -173,6 +149,8 @@ module.exports = {
'no-only-tests/no-only-tests': 'error',

// eslint:all rules to modify
'one-var': 'off',
'default-case': 'off',
'sort-keys': 'off',
'capitalized-comments': 'off',
'func-style': [
Expand All @@ -182,7 +160,6 @@ module.exports = {
allowArrowFunctions: true,
},
],
'no-negated-condition': 'off',
'multiline-comment-style': 'off',
'no-magic-numbers': [
'error',
Expand Down Expand Up @@ -246,17 +223,24 @@ module.exports = {
},
],
'no-ternary': 'off',

// this should use the default (3) but would currently cause too much pain
'max-params': ['error', 8],

// this should be turned on if the ignoreTopLevelFunctions option starts working
'max-statements': 'off',
'max-statements-per-line': 'off',
'consistent-return': 'off',
'no-undef': 'off',
'init-declarations': 'off',
'no-inline-comments': 'off',
'line-comment-position': 'off',
'prefer-destructuring': 'off',
'no-useless-return': 'off',

// use the sonarjs version instead
complexity: 'off',

// thanks to Prettier, we don't rely on automatic semicolon insertion, so this can remain off
'no-plusplus': 'off',

'max-lines': [
'error',
{
Expand All @@ -265,18 +249,14 @@ module.exports = {
skipComments: true,
},
],

'id-length': [
'error',
{
properties: 'never',
exceptions: ['_'],
},
],
// as long as we don't rely on ASI this can remain off
'no-plusplus': 'off',
'default-case': 'off',
'no-continue': 'off',
'callback-return': ['error', ['callback', 'cb']],
'new-cap': [
'error',
{
Expand Down Expand Up @@ -323,6 +303,7 @@ module.exports = {
'sonarjs/no-identical-functions': 'off',
'sonarjs/cognitive-complexity': 'off',
'max-lines': 'off',
'max-statements': 'off',
'no-await-in-loop': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
Expand All @@ -341,6 +322,7 @@ module.exports = {
'require-yield': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'n/no-process-env': 'off',
},
},
{
Expand Down
Loading
Loading