Skip to content

Commit

Permalink
feature: @putout/plugin-types: declare: isArray, isEmptyArray: add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Apr 21, 2024
1 parent 5fa1a1c commit bd2e919
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Supported assertions:
- `isSymbol`;
- `isNull`;
- `isBigInt`;
- `isArray`;
- `isEmptyArray`;

#### ❌ Example of incorrect code

Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-types/lib/declare/fixture/is-array-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const {isArray} = Array;
isArray(x);
1 change: 1 addition & 0 deletions packages/plugin-types/lib/declare/fixture/is-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isArray(x);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const {isArray} = Array;
const isEmptyArray = (a) => isArray(a) && !a.length;
isEmptyArray(x);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isEmptyArray(x);
2 changes: 2 additions & 0 deletions packages/plugin-types/lib/declare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ module.exports.declare = () => ({
isSymbol: `const isSymbol = (a) => typeof a === 'symbol'`,
isBigInt: `const isBigInt = (a) => typeof a === 'bigint'`,
isNull: `const isNull = (a) => !a && typeof a === 'object'`,
isArray: 'const {isArray} = Array',
isEmptyArray: 'const isEmptyArray = (a) => isArray(a) && !a.length',
});
10 changes: 10 additions & 0 deletions packages/plugin-types/lib/declare/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ test('putout: plugin: types: declare: is-symbol', (t) => {
t.transform('is-symbol');
t.end();
});

test('putout: plugin: types: declare: is-array', (t) => {
t.transform('is-array');
t.end();
});

test('putout: plugin: types: declare: is-empty-array', (t) => {
t.transform('is-empty-array');
t.end();
});
1 change: 1 addition & 0 deletions packages/plugin-types/test/fixture/apply-is-array-fix.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const {isArray} = Array;
isArray([1, 2, 3]);
isArray(x);

0 comments on commit bd2e919

Please sign in to comment.