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

Add eslint linter #1599

Merged
merged 2 commits into from
Nov 1, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- run: npm cache clean --force
- run: npm ci
- run: npm run build --if-present
- run: npm run lint

Upload_Coverage_Report:
name: Upload coverage report to codecov
Expand Down
40 changes: 17 additions & 23 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
src
**/*.js.map
test
typings
bundled
build
temp
coverage
docs
wiki
gulpfile.js
bower.json
mocha.opts
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
CODE_OF_CONDUCT.md
tslint.json
wallaby.js
.auditignore
.nyc_output
.github
.gitignore
.nyc_output
.publishrc
.travis.yml
.vscode
type_definitions
**/*.js.map
build
CODE_OF_CONDUCT.md
CONTRIBUTING.md
coverage
docs
eslint.config.mjs
ISSUE_TEMPLATE.md
mocha.opts
prettier.config.mjs
PULL_REQUEST_TEMPLATE.md
src
temp
test
tsconfig.json
wiki
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
![](https://raw.githubusercontent.com/inversify/inversify.github.io/master/img/cover.jpg)

<p align="center">
<a href="https://www.npmjs.com/package/inversify" target="__blank"><img src="https://img.shields.io/npm/v/inversify?color=0476bc&label=" alt="NPM version"></a>
<a href="https://www.npmjs.com/package/inversify" target="__blank"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/inversify?color=3890aa&label="></a>
<a href="https://github.com/inversify/InversifyJS#-the-inversifyjs-features-and-api" target="__blank"><img src="https://img.shields.io/static/v1?label=&message=docs&color=1e8a7a" alt="Docs"></a>
<a href="https://codecov.io/gh/inversify/InversifyJS" target="__blank"><img alt="Codecov" src="https://codecov.io/gh/inversify/InversifyJS/branch/master/graph/badge.svg?token=KfAKzuGs01"></a>
<br>
<br>
<a href="https://github.com/inversify/InversifyJS" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/inversify/InversifyJS?style=social"></a>
<!--<a href="https://twitter.com/inversifyjs" target="__blank"><img alt="Twitter" src="https://img.shields.io/twitter/follow/InversifyJS.svg?maxAge=86400&style=social"></a>-->
<a href="https://discord.gg/jXcMagAPnm" target="__blank"><img alt="Discord Server" src="https://img.shields.io/discord/816766547879657532?style=social&logo=discord"></a>
<a href="https://www.npmjs.com/package/inversify" target="__blank"><img src="https://img.shields.io/npm/v/inversify?color=0476bc&label=" alt="NPM version"></a>
<a href="https://www.npmjs.com/package/inversify" target="__blank"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/inversify?color=3890aa&label="></a>
<a href="https://github.com/inversify/InversifyJS#-the-inversifyjs-features-and-api" target="__blank"><img src="https://img.shields.io/static/v1?label=&message=docs&color=1e8a7a" alt="Docs"></a>
<a href="https://codecov.io/gh/inversify/InversifyJS" target="__blank"><img alt="Codecov" src="https://codecov.io/gh/inversify/InversifyJS/branch/master/graph/badge.svg?token=KfAKzuGs01"></a>
<br>
<br>
<a href="https://github.com/inversify/InversifyJS" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/inversify/InversifyJS?style=social"></a>
<!--<a href="https://twitter.com/inversifyjs" target="__blank"><img alt="Twitter" src="https://img.shields.io/twitter/follow/InversifyJS.svg?maxAge=86400&style=social"></a>-->
<a href="https://discord.gg/jXcMagAPnm" target="__blank"><img alt="Discord Server" src="https://img.shields.io/discord/816766547879657532?style=social&logo=discord"></a>
</p>

# InversifyJS
Expand Down Expand Up @@ -176,9 +176,9 @@ class Ninja implements Warrior {
private _katana: Weapon;
private _shuriken: ThrowableWeapon;

public constructor(
@inject(TYPES.Weapon) katana: Weapon,
@inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
constructor(
@inject(TYPES.Weapon) katana: Weapon,
@inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
) {
this._katana = katana;
this._shuriken = shuriken;
Expand Down
177 changes: 177 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPrettierConfig from 'eslint-plugin-prettier/recommended';
import simpleImportSort from 'eslint-plugin-simple-import-sort';

/**
* @returns {import('typescript-eslint').ConfigWithExtends}
*/
function buildBaseConfig() {
return {
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: './tsconfig.json',
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
'simple-import-sort': simpleImportSort,
},
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
overrides: {
constructors: 'no-public',
},
},
],
'@typescript-eslint/member-ordering': ['warn'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: ['classProperty'],
format: ['strictCamelCase', 'UPPER_CASE', 'snake_case'],
leadingUnderscore: 'allow',
},
{
selector: 'typeParameter',
format: ['StrictPascalCase'],
prefix: ['T'],
},
{
selector: ['typeLike'],
format: ['StrictPascalCase'],
},
{
selector: ['function', 'classMethod'],
format: ['strictCamelCase'],
leadingUnderscore: 'allow',
},
{
selector: ['parameter'],
format: ['strictCamelCase'],
leadingUnderscore: 'allow',
},
{
selector: ['variableLike'],
format: ['strictCamelCase', 'UPPER_CASE', 'snake_case'],
},
],
'@typescript-eslint/no-deprecated': 'error',
'@typescript-eslint/no-duplicate-type-constituents': 'off',
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-empty-interface': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': [
'warn',
{
ignore: [0, 1],
ignoreArrayIndexes: true,
ignoreEnums: true,
ignoreReadonlyClassProperties: true,
},
],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
'@typescript-eslint/no-unused-expressions': ['error'],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['off'],
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-readonly': ['warn'],
'@typescript-eslint/promise-function-async': ['error'],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': [
'error',
{
skipCompoundAssignments: false,
},
],
'@typescript-eslint/typedef': [
'error',
{
arrayDestructuring: true,
arrowParameter: true,
memberVariableDeclaration: true,
objectDestructuring: true,
parameter: true,
propertyDeclaration: true,
variableDeclaration: true,
},
],
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/strict-boolean-expressions': 'error',
'@typescript-eslint/switch-exhaustiveness-check': [
'error',
{
considerDefaultExhaustiveForUnions: true,
},
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'simple-import-sort/imports': [
'error',
{
groups: [['^\\u0000'], ['^node:'], ['^@?\\w'], ['^'], ['^\\.']],
},
],
'sort-keys': [
'error',
'asc',
{
caseSensitive: false,
natural: true,
},
],
},
};
}

const baseRules = buildBaseConfig();

const config = tseslint.config(
{
...baseRules,
files: ['**/*.ts'],
ignores: ['**/*.test.ts'],
},
{
...baseRules,
files: ['**/*.test.ts'],
rules: {
...(baseRules.rules ?? {}),
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
},
},
/** @type {import('typescript-eslint').ConfigWithExtends} */ (
eslintPrettierConfig
),
);

export default [...config];
Loading