Skip to content

Commit 1aa1c20

Browse files
committed
Add customized example
1 parent 3f8ae33 commit 1aa1c20

File tree

8 files changed

+2883
-2
lines changed

8 files changed

+2883
-2
lines changed

.github/workflows/test.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ jobs:
2424
run: npm test
2525
- name: Build TypeScript files
2626
run: npm run build
27-
- name: Test ESLint 9 example for compatibility
27+
- name: Test ESLint 9 recommended example for compatibility
2828
run: |
2929
cd examples/recommended
3030
npm ci
3131
(npm run lint || true) | grep -aq "Type of name in User is not matching the TypeORM column type (expected type: string)"
32+
- name: Test ESLint 9 customized example for compatibility
33+
run: |
34+
cd examples/customized
35+
npm ci
36+
(npm run lint || true) | grep -aq "The nullability of name in User should be set to the default value"
3237
- name: Test legacy example for compatibility
3338
run: |
34-
# Workaround until they fix scoping
39+
# Workaround for scoping preferring new config files
3540
mv eslint.config.mjs _eslint.config.mjs
3641
cd examples/legacy
3742
npm ci

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Changed
66

7+
- Fix circular dependecy issue between plugin and recommended, making customization fail
8+
- Add `customized` example (with tests) to display the customization options
79
- **Breaking**: `bigint` and `decimal` are now parsed correctly according to the driver ([#5](https://github.com/daniel7grant/eslint-plugin-typeorm-typescript/issues/5#issuecomment-2452988205))
810
- There is new option `driver` for `enforce-column-types`: can be 'postgres', 'mysql' or 'sqlite'
911
- If the driver is empty (default) or set to MySQL and PostgreSQL, bigint and decimal are parsed to be strings

examples/customized/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Flat configuration
2+
3+
This is the new way to configure ESLint ("flat configuration"). Supported from ESLint >= 9.
4+
5+
## Usage
6+
7+
Install the package for the plugin:
8+
9+
```sh
10+
npm install -D eslint-plugin-typeorm-typescript
11+
```
12+
13+
Add the recommended configuration to `eslint.config.mjs`:
14+
15+
```js
16+
import eslint from '@eslint/js';
17+
import tseslint from 'typescript-eslint';
18+
import typeormTypescriptRecommended from 'eslint-plugin-typeorm-typescript/recommended';
19+
20+
export default tseslint.config(
21+
eslint.configs.recommended,
22+
...tseslint.configs.recommended,
23+
typeormTypescriptRecommended,
24+
);
25+
```
26+
27+
If you want to change the options, enable the plugin and the rules manually:
28+
29+
```js
30+
import eslint from '@eslint/js';
31+
import tseslint from 'typescript-eslint';
32+
import typeormTypescriptPlugin from 'eslint-plugin-typeorm-typescript';
33+
34+
export default tseslint.config(
35+
eslint.configs.recommended,
36+
...tseslint.configs.recommended,
37+
{
38+
plugins: {'typeorm-typescript': typeormTypescriptPlugin},
39+
rules: {
40+
"typeorm-typescript/enforce-column-types": "error",
41+
"typeorm-typescript/enforce-relation-types": "warn",
42+
"typeorm-typescript/enforce-consistent-nullability": ["error", { "specifyNullable": "always" }]
43+
}
44+
}
45+
);
46+
```

examples/customized/eslint.config.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import tseslint from 'typescript-eslint';
5+
import typeormTypescriptPlugin from 'eslint-plugin-typeorm-typescript';
6+
7+
export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, {
8+
plugins: {
9+
'typeorm-typescript': typeormTypescriptPlugin,
10+
},
11+
rules: {
12+
'typeorm-typescript/enforce-column-types': [
13+
'error',
14+
// It will check bigint and decimal correctly
15+
{ driver: 'sqlite' },
16+
],
17+
'typeorm-typescript/enforce-relation-types': [
18+
'error',
19+
// It will force Relation<...> wrappers
20+
{ specifyRelation: 'always' }
21+
],
22+
'typeorm-typescript/enforce-consistent-nullability': [
23+
'error',
24+
// It will force nullable everywhere
25+
{ specifyNullable: 'always' },
26+
],
27+
},
28+
});

examples/customized/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Entity, Column, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
2+
3+
@Entity()
4+
export class Post {
5+
@PrimaryGeneratedColumn()
6+
id: number;
7+
8+
@Column({ type: 'number' })
9+
userId: number;
10+
}
11+
12+
@Entity()
13+
export class User {
14+
@PrimaryGeneratedColumn()
15+
id: number;
16+
17+
@Column({ type: 'string' })
18+
name: number;
19+
20+
@Column({ type: 'decimal' })
21+
wage: string;
22+
23+
@OneToMany(() => Post, (post) => post.userId)
24+
posts: Post;
25+
}

0 commit comments

Comments
 (0)