-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more mutators; groundwork for multi-mutators
- Loading branch information
Showing
19 changed files
with
166 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const R = require("ramda"); | ||
const { Syntax } = require("estraverse"); | ||
|
||
const dropItem = require("../util/drop-item"); | ||
|
||
import { MutatorPlugin } from "../types"; | ||
|
||
module.exports = <MutatorPlugin>{ | ||
// drops the first declared element in an array literal | ||
// `['a', 'b']` => `['a']` | ||
name: "tweak-arguments", | ||
nodeTypes: [Syntax.CallExpression], | ||
filter: function (node) { | ||
return R.path(["arguments", "length"], node) !== 0; | ||
}, | ||
mutator: function (node) { | ||
return dropItem(node, "arguments", "first"); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { Syntax } = require("estraverse"); | ||
const R = require("ramda"); | ||
|
||
const dropItem = require("../util/drop-item"); | ||
|
||
import { MutatorPlugin } from "../types"; | ||
|
||
module.exports = <MutatorPlugin>{ | ||
name: "tweak-switch", | ||
nodeTypes: [Syntax.SwitchStatement], | ||
filter: function (node) { | ||
return R.path(["cases", "length"], node) !== 0; | ||
}, | ||
mutator: function (node) { | ||
return dropItem(node, "cases", "first"); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
///<reference path="../../typings/modules/ramda/index.d.ts"/> | ||
|
||
// extra block-scope hack to account for "error TS2451: Cannot redeclare block-scoped variable 'R'" (???) | ||
{ | ||
|
||
const R = require("ramda"); | ||
|
||
type DropStrategy = "first" | "last" | "random" | ||
|
||
const strategyMap = { | ||
first: function(node: ESTree.Node, key: string) { | ||
return R.assoc(key, node[key].slice(1), node); | ||
}, | ||
last: function(node: ESTree.Node, key: string) { | ||
return R.assoc(key, node[key].slice(0, -1), node); | ||
}, | ||
random: function(node: ESTree.Node, key: string) { | ||
return R.assoc(key, dropRandom(node[key]), node); | ||
}, | ||
} | ||
|
||
function getRandomIndex (arr: any[]) { | ||
return Math.floor(Math.random() * (arr.length)) | ||
} | ||
|
||
function dropRandom (arr: any[]) { | ||
return R.remove(getRandomIndex(arr), 1, arr); | ||
} | ||
|
||
function dropItemOfKey (node: ESTree.Node, key: string, strategy: DropStrategy) { | ||
return strategyMap[strategy](node, key); | ||
} | ||
|
||
module.exports = dropItemOfKey; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
///<reference path="../../typings/modules/ramda/index.d.ts"/> | ||
|
||
{ | ||
|
||
const R = require("ramda"); | ||
|
||
function mapRemoveKeyItem (key, obj) { | ||
return obj[key].map(function (_, i) { | ||
return R.assoc(key, R.remove(i, 1, obj[key]), obj); | ||
}); | ||
} | ||
|
||
module.exports = R.curry(mapRemoveKeyItem); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mutators | ||
- drop last argument of function | ||
- drop a case from a switch statement | ||
|
||
|
||
API | ||
- how to skip or mark OK? i.e. "reverse-function-parameters" applied to (a, b) => a + b will not report a failure, but it is ok | ||
|
Empty file.
Oops, something went wrong.