@1024pix/eslint-plugin 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ name: Check node version availability on Scalingo
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ check-node-compatibility:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Checkout Repository
10
+ uses: actions/checkout@v4
11
+
12
+ - uses: 1024pix/pix-actions/check-node-version-availability-on-scalingo@v0
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 20.13.0
1
+ 20.18.1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # [2.0.0](https://github.com/1024pix/eslint-plugin/compare/v1.3.0...v2.0.0) (2024-12-19)
2
+
3
+ ### :boom: BREAKING CHANGE
4
+
5
+ - [#13](https://github.com/1024pix/eslint-plugin/pull/13) Montée de version d'ESLint en V9
6
+
7
+ ### :rewind: Retour en arrière
8
+
9
+ - [#33](https://github.com/1024pix/eslint-plugin/pull/33) Update dependency node to v20.17.0
10
+
11
+ ### :arrow_up: Montée de version
12
+
13
+ - [#31](https://github.com/1024pix/eslint-plugin/pull/31) Lock file maintenance
14
+ - [#43](https://github.com/1024pix/eslint-plugin/pull/43) Lock file maintenance (dossier racine)
15
+ - [#42](https://github.com/1024pix/eslint-plugin/pull/42) Lock file maintenance (dossier racine)
16
+ - [#40](https://github.com/1024pix/eslint-plugin/pull/40) Lock file maintenance (dossier racine)
17
+ - [#39](https://github.com/1024pix/eslint-plugin/pull/39) Lock file maintenance (dossier racine)
18
+ - [#37](https://github.com/1024pix/eslint-plugin/pull/37) Lock file maintenance (dossier racine)
19
+ - [#30](https://github.com/1024pix/eslint-plugin/pull/30) Update dependency node to v20.16.0
20
+ - [#34](https://github.com/1024pix/eslint-plugin/pull/34) Update dependency node to v20.17.0
21
+ - [#32](https://github.com/1024pix/eslint-plugin/pull/32) Update dependency node to v20.17.0
22
+ - [#36](https://github.com/1024pix/eslint-plugin/pull/36) Update dependency node to v20.18.0
23
+ - [#41](https://github.com/1024pix/eslint-plugin/pull/41) Update Node.js to v20.18.1
24
+
1
25
  # [1.3.0](https://github.com/1024pix/eslint-plugin/compare/v1.2.2...v1.3.0) (2024-07-16)
2
26
 
3
27
  ### :rocket: Amélioration
package/config.js CHANGED
@@ -87,7 +87,6 @@ module.exports = [
87
87
  },
88
88
  ],
89
89
  '@1024pix/no-sinon-stub-with-args-oneliner': 'error',
90
- '@1024pix/no-column-migration-without-comment': 'error',
91
90
  },
92
91
  },
93
92
  ];
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
- 'use strict';
2
- const noSinonStubWithArgsOneliner = require('./rules/no-sinon-stub-with-args-oneliner.js');
3
- const noColumnMigrationWithoutComment = require('./rules/no-column-migration-without-comment.js');
1
+ import noSinonStubWithArgsOneliner from './rules/no-sinon-stub-with-args-oneliner.js';
4
2
 
5
- module.exports = {
6
- rules: { 'no-sinon-stub-with-args-oneliner': noSinonStubWithArgsOneliner, 'no-column-migration-without-comment': noColumnMigrationWithoutComment },
3
+ export default {
4
+ rules: { 'no-sinon-stub-with-args-oneliner': noSinonStubWithArgsOneliner },
7
5
  };
package/package.json CHANGED
@@ -1,24 +1,30 @@
1
1
  {
2
2
  "name": "@1024pix/eslint-plugin",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "Des règles de lint pour les projets 1024pix",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": "^20 || ^22"
8
+ },
5
9
  "exports": {
6
10
  ".": "./index.js",
7
11
  "./config": "./config.js"
8
12
  },
9
13
  "scripts": {
10
- "test": "node rules/*.test.js"
14
+ "test": "ava"
11
15
  },
12
16
  "dependencies": {
13
- "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
14
- "eslint-plugin-simple-import-sort": "^12.1.0",
15
- "eslint-plugin-yml": "^1.14.0"
17
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
18
+ "eslint-plugin-simple-import-sort": "^12.1.1",
19
+ "eslint-plugin-yml": "^1.16.0"
16
20
  },
17
21
  "devDependencies": {
18
- "eslint": "^8.57.0"
22
+ "ava": "^6.2.0",
23
+ "eslint": "^9.17.0",
24
+ "eslint-ava-rule-tester": "^5.0.1"
19
25
  },
20
26
  "peerDependencies": {
21
- "eslint": ">=8.56.0"
27
+ "eslint": ">=9.17.0"
22
28
  },
23
29
  "repository": {
24
30
  "type": "git",
package/readme.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ### Install
8
8
 
9
9
  ```bash
10
- npm install --save-dev eslint@^8 @1024pix/eslint-plugin
10
+ npm install --save-dev eslint@^9 @1024pix/eslint-plugin
11
11
  ```
12
12
 
13
13
  ### Config `eslint.config.cjs`
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  function report(context, node) {
4
2
  context.report({
5
3
  node: node,
@@ -7,36 +5,32 @@ function report(context, node) {
7
5
  });
8
6
  }
9
7
 
10
- module.exports = {
8
+ export default {
11
9
  meta: {
12
10
  type: 'problem',
13
11
  docs: {
14
- description:
15
- 'Do not chain `sinon.stub()` with the `withArgs()` method in a one-liner',
12
+ description: 'Do not chain `sinon.stub()` with the `withArgs()` method in a one-liner',
16
13
  },
17
14
  messages: {
18
- chainError:
19
- '`sinon.stub()` should not be chained with the `withArgs` method.',
15
+ chainError: '`sinon.stub()` should not be chained with the `withArgs` method.',
20
16
  },
21
17
  },
22
- create: function (context) {
23
- return {
24
- 'VariableDeclarator > CallExpression > MemberExpression[property.name="returns"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
25
- function (node) {
26
- report(context, node);
27
- },
28
- 'VariableDeclarator > CallExpression > MemberExpression[property.name="throws"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
29
- function (node) {
30
- report(context, node);
31
- },
32
- 'VariableDeclarator > CallExpression > MemberExpression[property.name="resolves"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
33
- function (node) {
34
- report(context, node);
35
- },
36
- 'VariableDeclarator > CallExpression > MemberExpression[property.name="rejects"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
37
- function (node) {
38
- report(context, node);
39
- },
40
- };
41
- },
18
+ create: (context) => ({
19
+ 'VariableDeclarator > CallExpression > MemberExpression[property.name="returns"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
20
+ (node) => {
21
+ report(context, node);
22
+ },
23
+ 'VariableDeclarator > CallExpression > MemberExpression[property.name="throws"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
24
+ (node) => {
25
+ report(context, node);
26
+ },
27
+ 'VariableDeclarator > CallExpression > MemberExpression[property.name="resolves"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
28
+ (node) => {
29
+ report(context, node);
30
+ },
31
+ 'VariableDeclarator > CallExpression > MemberExpression[property.name="rejects"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
32
+ (node) => {
33
+ report(context, node);
34
+ },
35
+ }),
42
36
  };
@@ -1,11 +1,9 @@
1
- 'use strict';
1
+ import test from 'ava';
2
+ import AvaRuleTester from 'eslint-ava-rule-tester';
2
3
 
3
- const rule = require('./no-sinon-stub-with-args-oneliner.js'),
4
- RuleTester = require('eslint').RuleTester;
4
+ import rule from './no-sinon-stub-with-args-oneliner.js';
5
5
 
6
- const ruleTester = new RuleTester({
7
- parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
8
- });
6
+ const ruleTester = new AvaRuleTester(test);
9
7
 
10
8
  ruleTester.run('no-sinon-stub-with-args-oneliner', rule, {
11
9
  valid: [
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- function report(context, node) {
4
- context.report({
5
- node: node,
6
- messageId: 'chainError',
7
- });
8
- }
9
-
10
-
11
- function getIdentifierName(node, stackName = []) {
12
- switch (node.type) {
13
- case 'Identifier':
14
- return { identifier: node.name, callStack: stackName };
15
- case 'MemberExpression':
16
- return getIdentifierName(node.object, [...stackName, node.property.name])
17
- case 'CallExpression':
18
- return getIdentifierName(node.callee, stackName);
19
- case 'AwaitExpression':
20
- return getIdentifierName(node.argument, stackName);
21
- }
22
- }
23
-
24
- const VALID_MEMBER_EXPRESSIONS = ['dropColumn', 'foreign', 'unique', 'index', 'dropUnique', 'dropIndex'];
25
-
26
- module.exports = {
27
- meta: {
28
- type: 'problem',
29
- docs: {
30
- description:
31
- 'All columns should have a comment explaining their purpose',
32
- },
33
- messages: {
34
- chainError:
35
- '`table.column()` should have a comment explaining its purpose',
36
- },
37
- },
38
- create: function(context) {
39
- return {
40
- CallExpression(node) {
41
- const { callee } = node;
42
-
43
- if (
44
- callee.type === 'MemberExpression' &&
45
- callee.object &&
46
- callee.object.object &&
47
- callee.object.object.name === 'knex' &&
48
- callee.object.property &&
49
- callee.object.property.name === 'schema' &&
50
- ['alterTable', 'createTable', 'table'].includes(callee.property.name)
51
- ) {
52
- const callback = node.arguments[1];
53
-
54
- if (callback && callback.type === 'ArrowFunctionExpression') {
55
- const tableParam = callback.params[0];
56
-
57
- if (tableParam && tableParam.type === 'Identifier') {
58
-
59
- const body = callback.body.body ?? [{ expression: callback.body }];
60
-
61
- body.forEach(statement => {
62
- const columnExpression = statement.expression;
63
-
64
- const { identifier: identifierName, callStack } = getIdentifierName(columnExpression);
65
-
66
- if (!callStack.some((call) => VALID_MEMBER_EXPRESSIONS.includes(call))) {
67
- if (identifierName === tableParam.name) {
68
- const hasComment = callStack.includes('comment');
69
-
70
- if (!hasComment) {
71
- report(context, node);
72
- }
73
- }
74
- }
75
-
76
- });
77
- }
78
- }
79
- }
80
- }
81
- };
82
- }
83
- };
@@ -1,260 +0,0 @@
1
- 'use strict';
2
-
3
- const rule = require('./no-column-migration-without-comment.js'),
4
- RuleTester = require('eslint').RuleTester;
5
-
6
- const ruleTester = new RuleTester({
7
- parserOptions: { ecmaVersion: 2021, sourceType: 'module' },
8
- });
9
-
10
- ruleTester.run('no-column-migration-without-comment', rule, {
11
- valid: [
12
- // createTable
13
- {
14
- name: 'With comment',
15
- code: `
16
- const up = function (knex) {
17
- return knex.schema.createTable(TABLE_NAME, (table) => {
18
- table.boolean(COLUMN_NAME).comment('This is a comment');
19
- });
20
- };
21
- `,
22
- },
23
-
24
- {
25
- name: 'Without using table callback',
26
- code: `
27
- const up = function (knex) {
28
- return knex.schema.createTable(TABLE_NAME, (table) => {
29
- toto.maFunction();
30
- });
31
- };
32
- `,
33
- },
34
-
35
- // alterTable
36
- {
37
- name: 'With comment',
38
- code: `
39
- const up = function (knex) {
40
- return knex.schema.alterTable(TABLE_NAME, (table) => {
41
- table.boolean(COLUMN_NAME).comment('This is a comment');
42
- });
43
- };
44
- `,
45
- },
46
-
47
- {
48
- name: 'Without using table callback',
49
- code: `
50
- const up = function (knex) {
51
- return knex.schema.alterTable(TABLE_NAME, (table) => {
52
- toto.maFunction();
53
- });
54
- };
55
- `,
56
- },
57
-
58
- // table
59
-
60
- {
61
- name: 'With comment',
62
- code: `
63
- const up = function (knex) {
64
- return knex.schema.table(TABLE_NAME, (table) => {
65
- table.boolean(COLUMN_NAME).comment('This is a comment');
66
- });
67
- };
68
- `,
69
- },
70
-
71
- {
72
- name: 'Without using table callback',
73
- code: `
74
- const up = function (knex) {
75
- return knex.schema.table(TABLE_NAME, (table) => {
76
- toto.maFunction();
77
- });
78
- };
79
- `,
80
- },
81
-
82
-
83
- {
84
- name: 'With down function',
85
- code: `
86
- const down = function (knex) {
87
- return knex.schema.table(TABLE_NAME, (table) => {
88
- table.boolean('toto').comment('This is a comment');
89
- });
90
- };
91
- `,
92
- },
93
-
94
-
95
- {
96
- name: 'With dropColumn',
97
- code: `
98
- const up = function (knex) {
99
- return knex.schema.table(TABLE_NAME, (table) => {
100
- table.dropColumn('toto');
101
- });
102
- };
103
- `,
104
- },
105
-
106
- {
107
- name: 'With foreign',
108
- code: `
109
- const up = function (knex) {
110
- return knex.schema.table(TABLE_NAME, (table) => {
111
- table.foreign('toto');
112
- });
113
- };
114
- `,
115
- },
116
-
117
- {
118
- name: 'With unique',
119
- code: `
120
- const up = function (knex) {
121
- return knex.schema.table(TABLE_NAME, (table) => {
122
- table.unique('toto');
123
- });
124
- };
125
- `,
126
- },
127
-
128
- {
129
- name: 'With index',
130
- code: `
131
- const up = function (knex) {
132
- return knex.schema.table(TABLE_NAME, (table) => {
133
- table.index('toto');
134
- });
135
- };
136
- `,
137
- },
138
-
139
- {
140
- name: 'With dropUnique',
141
- code: `
142
- const up = function (knex) {
143
- return knex.schema.table(TABLE_NAME, (table) => {
144
- table.dropUnique('toto');
145
- });
146
- };
147
- `,
148
- },
149
-
150
- {
151
- name: 'With dropIndex',
152
- code: `
153
- const up = function (knex) {
154
- return knex.schema.table(TABLE_NAME, (table) => {
155
- table.dropIndex('toto');
156
- });
157
- };
158
- `,
159
- },
160
-
161
- {
162
- name: 'With oneliner',
163
- code: `
164
- const up = function (knex) {
165
- return knex.schema.table(TABLE_NAME, (table) => table.boolean('toto').comment('comment'));
166
- };
167
- `,
168
- },
169
-
170
- {
171
- name: 'With await',
172
- code: `
173
- const up = async function (knex) {
174
- return knex.schema.alterTable(TABLE_NAME, async (table) => {
175
- await table.decimal(COLUMN, 5, 2).notNullable().alter().comment('toto');
176
- });
177
- };
178
- `,
179
- },
180
- ],
181
-
182
- invalid: [
183
-
184
- // CreateTable
185
- {
186
- name: 'Create column without comment',
187
- code: `
188
- const up = function (knex) {
189
- return knex.schema.createTable(TABLE_NAME, (table) => {
190
- table.boolean(COLUMN_NAME).defaultTo(false);
191
- });
192
- };
193
- `,
194
- errors: [{ messageId: 'chainError' }],
195
- },
196
- {
197
- name: 'Create column without comment',
198
- code: `
199
- const up = function (knex) {
200
- return knex.schema.createTable(TABLE_NAME, (table) => {
201
- table.boolean(COLUMN_NAME).defaultTo(false).comment('toto');
202
- table.boolean(COLUMN_NAME_2).defaultTo(false);
203
- });
204
- };
205
- `,
206
- errors: [{ messageId: 'chainError' }],
207
- },
208
-
209
- // AlterTable
210
-
211
- {
212
- name: 'Create column without comment',
213
- code: `
214
- const up = function (knex) {
215
- return knex.schema.alterTable(TABLE_NAME, (table) => {
216
- table.boolean(COLUMN_NAME).defaultTo(false);
217
- });
218
- };
219
- `,
220
- errors: [{ messageId: 'chainError' }],
221
- },
222
- {
223
- name: 'Create column without comment',
224
- code: `
225
- const up = function (knex) {
226
- return knex.schema.alterTable(TABLE_NAME, (table) => {
227
- table.boolean(COLUMN_NAME).defaultTo(false).comment('toto');
228
- table.boolean(COLUMN_NAME_2).defaultTo(false);
229
- });
230
- };
231
- `,
232
- errors: [{ messageId: 'chainError' }],
233
- },
234
-
235
- // table
236
- {
237
- name: 'Create column without comment',
238
- code: `
239
- const up = function (knex) {
240
- return knex.schema.table(TABLE_NAME, (table) => {
241
- table.boolean(COLUMN_NAME).defaultTo(false);
242
- });
243
- };
244
- `,
245
- errors: [{ messageId: 'chainError' }],
246
- },
247
- {
248
- name: 'Create column without comment',
249
- code: `
250
- const up = function (knex) {
251
- return knex.schema.table(TABLE_NAME, (table) => {
252
- table.boolean(COLUMN_NAME).defaultTo(false).comment('toto');
253
- table.boolean(COLUMN_NAME_2).defaultTo(false);
254
- });
255
- };
256
- `,
257
- errors: [{ messageId: 'chainError' }],
258
- },
259
- ],
260
- });