Skip to content

Commit

Permalink
Merge pull request #15 from daniel7grant/feature/eslint92
Browse files Browse the repository at this point in the history
Add support for ESLint flat config and ESM
  • Loading branch information
daniel7grant authored Aug 9, 2024
2 parents 98b1d9c + df06da5 commit da8f474
Show file tree
Hide file tree
Showing 34 changed files with 6,611 additions and 906 deletions.
29 changes: 0 additions & 29 deletions .eslintrc.json

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ jobs:
run: npm test
- name: Build TypeScript files
run: npm run build
- name: Test ESLint 9 example for compatibility
run: |
cd examples/recommended
npm ci
(npm run lint || true) | grep -aq "Type of name in User is not matching the TypeORM column type (expected type: string)"
- name: Test legacy example for compatibility
run: |
# Workaround until they fix scoping
mv eslint.config.mjs _eslint.config.mjs
cd examples/legacy
npm ci
(npm run lint || true) | grep -aq "Type of name in User is not matching the TypeORM column type (expected type: string)"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist/
dist/*
!dist/package.json
es/
node_modules/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## [Unreleased]

### Added

- Add support for flat configuration
- Update `typescript-eslint` packages to v8
- Update `eslint` packages to v9
- There is a new export `eslint-plugin-typeorm-typescript/recommended`, for simple interfacing of the flat configuration
- Add dual ES Module and CommonJS support
- Add `tsconfig.es.json` to output ES Modules to `es/`
- Output CommonJS format to `dist/` (needs hack to set the `module` to `commonjs` in `package.json`)
- Add `exports` fields to `package.json` for `.` and `./recommended`
- Add extension to every import to comply with ES specification
- Add examples to be used as simple setup and end-to-end tests

## [0.3.1] - 2024-08-06

### Changed
Expand Down
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,48 @@ Install the package for the plugin:
npm install -D eslint-plugin-typeorm-typescript
```

Update `.eslintrc.json` with the plugin to the `plugins` key, and add it to the `rules`:
### Flat configuration

To enable all rules, add the recommended configuration for `eslint-plugin-typeorm-typescript` to `eslint.config.mjs`:

```js
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import typeormTypescriptRecommended from 'eslint-plugin-typeorm-typescript/recommended';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
typeormTypescriptRecommended,
);
```

If you want to change the options, enable the plugin and the rules manually:

```js
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import typeormTypescriptPlugin from 'eslint-plugin-typeorm-typescript';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {'typeorm-typescript': typeormTypescriptPlugin},
rules: {
"typeorm-typescript/enforce-column-types": "error",
"typeorm-typescript/enforce-relation-types": "warn",
"typeorm-typescript/enforce-consistent-nullability": ["error", { "specifyNullable": "always" }]
}
}
);
```

For more information, see an example of the [recommended configuration](./examples/recommended/).

### Legacy configuration

If you are still on legacy ESLint, update `.eslintrc.json` with the plugin to the `plugins` key, and add it to the `rules`:

```json
{
Expand All @@ -25,6 +66,8 @@ Update `.eslintrc.json` with the plugin to the `plugins` key, and add it to the
}
```

For more information, see an example of the [legacy configuration](./examples/legacy/).

## Rules

TypeORM has no way to statically analyze if there is an inconsistency in the annotated TypeScript types.
Expand Down
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.stylistic,
eslintPluginPrettierRecommended,
);
11 changes: 11 additions & 0 deletions examples/legacy/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'typeorm-typescript'],
root: true,
rules: {
'typeorm-typescript/enforce-column-types': 'error',
'typeorm-typescript/enforce-relation-types': 'error',
'typeorm-typescript/enforce-consistent-nullability': 'error',
},
};
24 changes: 24 additions & 0 deletions examples/legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Legacy configuration

This is the legacy configuration to be used with ESLint <= 8.

## Usage

Install the package for the plugin:

```sh
npm install -D eslint-plugin-typeorm-typescript
```

Add the plugins and rules to your `.eslintrc.json` or equivalent:

```json
{
"plugins": ["typeorm-typescript"],
"rules": {
"typeorm-typescript/enforce-column-types": "error",
"typeorm-typescript/enforce-relation-types": "error",
"typeorm-typescript/enforce-consistent-nullability": "error"
}
}
```
7 changes: 7 additions & 0 deletions examples/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Entity, Column } from 'typeorm';

@Entity({ name: 'User' })
export class User {
@Column({ type: 'string' })
name: number;
}
Loading

0 comments on commit da8f474

Please sign in to comment.