Skip to content

Commit e3ffee0

Browse files
committed
feature: @putout/plugin-assignment: add
1 parent a5615c6 commit e3ffee0

File tree

100 files changed

+426
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+426
-892
lines changed

README.md

+1-5

packages/eslint-plugin-putout/.madrun.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const MOCHA_TIMEOUT = 20_000;
55

66
const env = {
77
SUPERTAPE_LOAD_LOOP_TIMEOUT,
8+
SUPERTAPE_PROGRESS_BAR_MIN: 10,
89
};
910

1011
const lintEnv = {
@@ -13,9 +14,9 @@ const lintEnv = {
1314

1415
export default {
1516
'wisdom': () => run(['lint:all', 'coverage']),
16-
'test': () => `tape 'test/**/*.mjs' 'lib/config/*.spec.*'`,
17+
'test': () => [env, `tape 'test/**/*.mjs' 'lib/config/*.spec.*'`],
1718
'test:all': () => [env, `mocha --timeout ${MOCHA_TIMEOUT} 'test/**/*.mjs' 'lib/putout/*.spec.js' 'lib/**/*.spec.js'`],
18-
'watch:test': async () => `nodemon -w rules -x "${await run('test')}"`,
19+
'watch:test': async () => [env, `nodemon -w rules -x "${await cutEnv('test')}"`],
1920
'lint': () => 'putout .',
2021
'lint:all': () => run(['lint', 'lint:safe']),
2122
'lint:safe': () => [lintEnv, 'putout eslint-fixture'],

packages/eslint-plugin-putout/lib/putout/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ parserTester.run('putout', rule, {
248248
code: `a = is() ? a : b`,
249249
options: [{
250250
rules: {
251-
'convert-assignment-to-declaration': 'off',
251+
'assignment/convert-to-declaration': 'off',
252252
},
253253
}],
254254
output: montag`

packages/plugin-convert-assignment-to-arrow-function/.madrun.mjs packages/plugin-assignment/.madrun.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {run} from 'madrun';
22

33
export default {
4-
'test': () => `tape 'test/*.js'`,
5-
'watch:test': async () => `nodemon -w lib -w test -x "${await run('test')}"`,
6-
'lint': () => `putout .`,
4+
'prepublishOnly': () => run(['lint', 'test']),
5+
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
6+
'watch:test': async () => `nodemon -w lib -x "${await run('test')}"`,
7+
'lint': () => 'putout .',
78
'fresh:lint': () => run('lint', '--fresh'),
89
'lint:fresh': () => run('lint', '--fresh'),
910
'fix:lint': () => run('lint', '--fix'),

packages/plugin-convert-assignment-to-declaration/.npmignore packages/plugin-assignment/.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.*
2+
*.spec.js
23
test
4+
fixture
35
yarn-error.log
46

57
coverage

packages/plugin-assignment/README.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {matchToFlat} from '@putout/eslint-flat';
2+
import {safeAlign} from 'eslint-plugin-putout';
3+
import {defineConfig} from 'eslint/config';
4+
5+
export const match = {
6+
'*.md{js}': {
7+
'n/no-deprecated-api': 'off',
8+
'n/no-unsupported-features/node-builtins': 'off',
9+
},
10+
};
11+
12+
export default defineConfig([
13+
matchToFlat(match),
14+
safeAlign, {
15+
rules: {
16+
'no-useless-return': 'off',
17+
},
18+
},
19+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const convertToArrowFunction = require('.');
5+
6+
const test = createTest(__dirname, {
7+
plugins: [
8+
['assignment/convert-to-arrow-function', convertToArrowFunction],
9+
],
10+
});
11+
12+
test('plugin-assignment-convert-to-arrow-function: report: assignment', (t) => {
13+
t.report('assignment', 'Expected ArrowFunction instead of Assignment');
14+
t.end();
15+
});
16+
17+
test('plugin-assignment-convert-to-arrow-function: transform: assignment', (t) => {
18+
t.transform('assignment');
19+
t.end();
20+
});
21+
22+
test('plugin-assignment: convert-to-arrow-function: no transform: variable', (t) => {
23+
t.noTransform('variable');
24+
t.end();
25+
});
26+
27+
test('plugin-assignment: convert-to-arrow-function: no transform: member-expression', (t) => {
28+
t.noTransform('member-expression');
29+
t.end();
30+
});
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
'use strict';
22

33
const {createTest} = require('@putout/test');
4-
const convertAssignmentToComparison = require('..');
4+
const convertAssignmentToComparison = require('.');
55

66
const test = createTest(__dirname, {
77
plugins: [
8-
['convert-assignment-to-comparison', convertAssignmentToComparison],
8+
['assignment/convert-to-comparison', convertAssignmentToComparison],
99
],
1010
});
1111

12-
test('plugin-convert-assignment-to-comparison: report: assignment', (t) => {
12+
test('plugin-assignment: convert-to-comparison: report: assignment', (t) => {
1313
t.report('assignment', 'Expected comparison instead of assignment');
1414
t.end();
1515
});
1616

17-
test('plugin-convert-assignment-to-comparison: transform: assignment', (t) => {
17+
test('plugin-assignment: convert-to-comparison: transform: assignment', (t) => {
1818
t.transform('assignment');
1919
t.end();
2020
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const plugin = require('.');
5+
6+
const test = createTest(__dirname, {
7+
plugins: [
8+
['assignment/convert-to-declaration', plugin],
9+
],
10+
});
11+
12+
test('putout: plugin-assignment: convert-to-declaration: report', (t) => {
13+
t.report('convert-to-declaration', `Declare 'a' before assignment`);
14+
t.end();
15+
});
16+
17+
test('putout: plugin-assignment: convert-to-declaration: no report: nested', (t) => {
18+
t.noReport('nested');
19+
t.end();
20+
});
21+
22+
test('putout: plugin-assignment: convert-to-declaration: no report: keyword', (t) => {
23+
t.noReport('keyword');
24+
t.end();
25+
});
26+
27+
test('putout: plugin-assignment: convert-to-declaration: transform', (t) => {
28+
t.transform('convert-to-declaration');
29+
t.end();
30+
});
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
const convertToArrowFunction = require('./convert-to-arrow-function');
4+
const convertToComparison = require('./convert-to-comparison');
5+
const convertToDeclaration = require('./convert-to-declaration');
6+
const simplify = require('./simplify');
7+
const split = require('./split');
8+
9+
module.exports.rules = {
10+
'convert-to-arrow-function': convertToArrowFunction,
11+
'convert-to-comparison': convertToComparison,
12+
'convert-to-declaration': convertToDeclaration,
13+
'simplify': simplify,
14+
'split': split,
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const simplify = require('.');
5+
6+
const test = createTest(__dirname, {
7+
plugins: [
8+
['assignment/simplify', simplify],
9+
],
10+
});
11+
12+
test('plugin-assignment: simplify: report: assignment', (t) => {
13+
t.report('assignment', 'Simplify assignment');
14+
t.end();
15+
});
16+
17+
test('plugin-assignment: simplify: transform: assignment', (t) => {
18+
t.transform('assignment');
19+
t.end();
20+
});
21+
22+
test('plugin-assignment: simplify: no transform: declaration', (t) => {
23+
t.noTransform('declaration');
24+
t.end();
25+
});
26+
27+
test('plugin-assignment: simplify: no transform: iife', (t) => {
28+
t.noTransform('iife');
29+
t.end();
30+
});

0 commit comments

Comments
 (0)