Skip to content

Commit

Permalink
fix: import name reliance across various codemods
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jul 23, 2024
1 parent 7725bdf commit 6deeb9d
Show file tree
Hide file tree
Showing 26 changed files with 197 additions and 197 deletions.
4 changes: 2 additions & 2 deletions codemods/array-includes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export default function (options) {
const root = j(file.source);
let dirtyFlag = false;

removeImport('array-includes', root, j);
const { identifier } = removeImport('array-includes', root, j);

root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'includes',
name: identifier,
},
})
.forEach((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-array-buffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export default function (options) {
const root = j(file.source);
let dirtyFlag = false;

removeImport('is-array-buffer', root, j);
const { identifier } = removeImport('is-array-buffer', root, j);

// Replace isArrayBuffer calls with (foo instanceof ArrayBuffer)
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isArrayBuffer',
name: identifier,
},
})
.forEach((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-boolean-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-boolean-object', root, j);
const { identifier } = removeImport('is-boolean-object', root, j);

// Replace all calls to isBoolean with Object.prototype.toString.call
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isBoolean',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-date-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-date-object', root, j);
const { identifier } = removeImport('is-date-object', root, j);

// Replace all calls to isDate with Object.prototype.toString.call
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isDate',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-even/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-even', root, j);
const { identifier } = removeImport('is-even', root, j);

root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isEven',
name: identifier,
},
})
.forEach((path) => {
Expand Down
6 changes: 3 additions & 3 deletions codemods/is-negative-zero/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function (options) {

const root = j(file.source);

removeImport('is-negative-zero', root, j);
const { identifier } = removeImport('is-negative-zero', root, j);

root
.find(j.LogicalExpression, {
Expand All @@ -32,7 +32,7 @@ export default function (options) {
},
right: {
type: 'CallExpression',
callee: { name: 'isNegativeZero' },
callee: { name: identifier },
},
})
.replaceWith((path) => {
Expand All @@ -43,7 +43,7 @@ export default function (options) {
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isNegativeZero',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-number-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-number-object', root, j);
const { identifier } = removeImport('is-number-object', root, j);

// Replace all calls to isNumber with Object.prototype.toString.call
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isNumber',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-odd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-odd', root, j);
const { identifier } = removeImport('is-odd', root, j);

root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isOdd',
name: identifier,
},
})
.forEach((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-regexp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export default function (options) {
const root = j(file.source);
let dirtyFlag = false;

removeImport('is-regexp', root, j);
const { identifier } = removeImport('is-regexp', root, j);

// Replace isRegexp calls
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isRegexp',
name: identifier,
},
})
.forEach((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-string', root, j);
const { identifier } = removeImport('is-string', root, j);

// Replace all calls to isString with Object.prototype.toString.call
root
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: 'isString',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
4 changes: 2 additions & 2 deletions codemods/is-whitespace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default function (options) {
const j = jscodeshift;
const root = j(file.source);

removeImport('is-whitespace', root, j);
const { identifier } = removeImport('is-whitespace', root, j);

// Find the 'isWhitespace' function calls
root
.find(j.CallExpression, {
callee: {
name: 'isWhitespace',
name: identifier,
},
})
.replaceWith((path) => {
Expand Down
14 changes: 7 additions & 7 deletions test/fixtures/array-includes/case-1/before.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var includes = require("array-includes");
var banana = require("array-includes");
var assert = require("assert");
var arr = ["one", "two"];

var arr = [1, "foo", NaN, -0];

assert.equal(includes(arr, 0), true);
assert.equal(includes(arr, -0), true);
assert.equal(banana(arr, 0), true);
assert.equal(banana(arr, -0), true);

assert.equal(includes(arr, NaN), true);
assert.equal(banana(arr, NaN), true);

assert.equal(includes(arr, "foo", 0), true);
assert.equal(includes(arr, "foo", 1), true);
assert.equal(includes(arr, "foo", 2), false);
assert.equal(banana(arr, "foo", 0), true);
assert.equal(banana(arr, "foo", 1), true);
assert.equal(banana(arr, "foo", 2), false);
32 changes: 16 additions & 16 deletions test/fixtures/is-array-buffer/case-1/before.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
var assert = require('assert');
var isArrayBuffer = require('is-array-buffer');
var banana = require('is-array-buffer');

assert(!isArrayBuffer(function () {}));
assert(!isArrayBuffer(null));
assert(!banana(function () {}));
assert(!banana(null));
assert(
!isArrayBuffer(function* () {
!banana(function* () {
yield 42;
return Infinity;
}),
);
assert(!isArrayBuffer(Symbol('foo')));
assert(!isArrayBuffer(1n));
assert(!isArrayBuffer(Object(1n)));
assert(!banana(Symbol('foo')));
assert(!banana(1n));
assert(!banana(Object(1n)));

assert(!isArrayBuffer(new Set()));
assert(!isArrayBuffer(new WeakSet()));
assert(!isArrayBuffer(new Map()));
assert(!isArrayBuffer(new WeakMap()));
assert(!isArrayBuffer(new WeakRef({})));
assert(!isArrayBuffer(new FinalizationRegistry(() => {})));
assert(!isArrayBuffer(new SharedArrayBuffer()));
assert(!banana(new Set()));
assert(!banana(new WeakSet()));
assert(!banana(new Map()));
assert(!banana(new WeakMap()));
assert(!banana(new WeakRef({})));
assert(!banana(new FinalizationRegistry(() => {})));
assert(!banana(new SharedArrayBuffer()));

assert(isArrayBuffer(new ArrayBuffer()));
assert(banana(new ArrayBuffer()));

class MyArrayBuffer extends ArrayBuffer {}
assert(isArrayBuffer(new MyArrayBuffer()));
assert(banana(new MyArrayBuffer()));
32 changes: 16 additions & 16 deletions test/fixtures/is-array-buffer/case-2/before.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
var assert = require('assert');
import isArrayBuffer from 'is-array-buffer';
import banana from 'is-array-buffer';

assert(!isArrayBuffer(function () {}));
assert(!isArrayBuffer(null));
assert(!banana(function () {}));
assert(!banana(null));
assert(
!isArrayBuffer(function* () {
!banana(function* () {
yield 42;
return Infinity;
}),
);
assert(!isArrayBuffer(Symbol('foo')));
assert(!isArrayBuffer(1n));
assert(!isArrayBuffer(Object(1n)));
assert(!banana(Symbol('foo')));
assert(!banana(1n));
assert(!banana(Object(1n)));

assert(!isArrayBuffer(new Set()));
assert(!isArrayBuffer(new WeakSet()));
assert(!isArrayBuffer(new Map()));
assert(!isArrayBuffer(new WeakMap()));
assert(!isArrayBuffer(new WeakRef({})));
assert(!isArrayBuffer(new FinalizationRegistry(() => {})));
assert(!isArrayBuffer(new SharedArrayBuffer()));
assert(!banana(new Set()));
assert(!banana(new WeakSet()));
assert(!banana(new Map()));
assert(!banana(new WeakMap()));
assert(!banana(new WeakRef({})));
assert(!banana(new FinalizationRegistry(() => {})));
assert(!banana(new SharedArrayBuffer()));

assert(isArrayBuffer(new ArrayBuffer()));
assert(banana(new ArrayBuffer()));

class MyArrayBuffer extends ArrayBuffer {}
assert(isArrayBuffer(new MyArrayBuffer()));
assert(banana(new MyArrayBuffer()));
36 changes: 18 additions & 18 deletions test/fixtures/is-boolean-object/case-1/before.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var assert = require('assert');
var isBoolean = require('is-boolean-object');
var banana = require('is-boolean-object');

assert.notOk(isBoolean(undefined));
assert.notOk(isBoolean(null));
assert.notOk(isBoolean('foo'));
assert.notOk(isBoolean(function () {}));
assert.notOk(isBoolean([]));
assert.notOk(isBoolean({}));
assert.notOk(isBoolean(/a/g));
assert.notOk(isBoolean(new RegExp('a', 'g')));
assert.notOk(isBoolean(new Date()));
assert.notOk(isBoolean(42));
assert.notOk(isBoolean(NaN));
assert.notOk(isBoolean(Infinity));
assert.notOk(banana(undefined));
assert.notOk(banana(null));
assert.notOk(banana('foo'));
assert.notOk(banana(function () {}));
assert.notOk(banana([]));
assert.notOk(banana({}));
assert.notOk(banana(/a/g));
assert.notOk(banana(new RegExp('a', 'g')));
assert.notOk(banana(new Date()));
assert.notOk(banana(42));
assert.notOk(banana(NaN));
assert.notOk(banana(Infinity));

assert.ok(isBoolean(new Boolean(42)));
assert.ok(isBoolean(false));
assert.ok(isBoolean(Object(false)));
assert.ok(isBoolean(true));
assert.ok(isBoolean(Object(true)));
assert.ok(banana(new Boolean(42)));
assert.ok(banana(false));
assert.ok(banana(Object(false)));
assert.ok(banana(true));
assert.ok(banana(Object(true)));
36 changes: 18 additions & 18 deletions test/fixtures/is-boolean-object/case-2/before.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import assert from 'assert';
import isBoolean from 'is-boolean-object';
import banana from 'is-boolean-object';

assert.notOk(isBoolean(undefined));
assert.notOk(isBoolean(null));
assert.notOk(isBoolean('foo'));
assert.notOk(isBoolean(function () {}));
assert.notOk(isBoolean([]));
assert.notOk(isBoolean({}));
assert.notOk(isBoolean(/a/g));
assert.notOk(isBoolean(new RegExp('a', 'g')));
assert.notOk(isBoolean(new Date()));
assert.notOk(isBoolean(42));
assert.notOk(isBoolean(NaN));
assert.notOk(isBoolean(Infinity));
assert.notOk(banana(undefined));
assert.notOk(banana(null));
assert.notOk(banana('foo'));
assert.notOk(banana(function () {}));
assert.notOk(banana([]));
assert.notOk(banana({}));
assert.notOk(banana(/a/g));
assert.notOk(banana(new RegExp('a', 'g')));
assert.notOk(banana(new Date()));
assert.notOk(banana(42));
assert.notOk(banana(NaN));
assert.notOk(banana(Infinity));

assert.ok(isBoolean(new Boolean(42)));
assert.ok(isBoolean(false));
assert.ok(isBoolean(Object(false)));
assert.ok(isBoolean(true));
assert.ok(isBoolean(Object(true)));
assert.ok(banana(new Boolean(42)));
assert.ok(banana(false));
assert.ok(banana(Object(false)));
assert.ok(banana(true));
assert.ok(banana(Object(true)));
Loading

0 comments on commit 6deeb9d

Please sign in to comment.