Skip to content

Commit

Permalink
refactor: use object-style syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jul 5, 2022
1 parent 7eee725 commit 1a723c1
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 214 deletions.
52 changes: 29 additions & 23 deletions tests/fixtures/testers/rule-tester/modify-ast-at-first.js
Expand Up @@ -9,30 +9,36 @@
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
return {
"Program": function(node) {
node.body.push({
"type": "Identifier",
"name": "modified",
"range": [0, 8],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
module.exports = {
meta: {
type: "problem",
schema: []
},
create(context) {
return {
"Program": function(node) {
node.body.push({
"type": "Identifier",
"name": "modified",
"range": [0, 8],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
}
});
},
});
},

"Identifier": function(node) {
if (node.name === "bar") {
context.report({message: "error", node: node});
"Identifier": function(node) {
if (node.name === "bar") {
context.report({message: "error", node: node});
}
}
}
};
};
},
};
52 changes: 29 additions & 23 deletions tests/fixtures/testers/rule-tester/modify-ast-at-last.js
Expand Up @@ -9,30 +9,36 @@
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
return {
"Program:exit": function(node) {
node.body.push({
"type": "Identifier",
"name": "modified",
"range": [0, 8],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
module.exports = {
meta: {
type: "problem",
schema: []
},
create(context) {
return {
"Program:exit": function(node) {
node.body.push({
"type": "Identifier",
"name": "modified",
"range": [0, 8],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
}
});
},
});
},

"Identifier": function(node) {
if (node.name === "bar") {
context.report({message: "error", node: node});
"Identifier": function(node) {
if (node.name === "bar") {
context.report({message: "error", node: node});
}
}
}
};
};
},
};
22 changes: 14 additions & 8 deletions tests/fixtures/testers/rule-tester/modify-ast.js
Expand Up @@ -9,14 +9,20 @@
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
return {
"Identifier": function(node) {
node.name += "!";
module.exports = {
meta: {
type: "problem",
schema: []
},
create(context) {
return {
"Identifier": function(node) {
node.name += "!";

if (node.name === "bar!") {
context.report({message: "error", node: node});
if (node.name === "bar!") {
context.report({message: "error", node: node});
}
}
}
};
};
},
};
28 changes: 16 additions & 12 deletions tests/fixtures/testers/rule-tester/no-eval.js
Expand Up @@ -3,20 +3,24 @@
* @author Nicholas C. Zakas
*/

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {

"use strict";

return {
"CallExpression": function(node) {
if (node.callee.name === "eval") {
context.report(node, "eval sucks.");
}
}
};

module.exports = {
meta: {
type: "problem",
schema: [],
},
create(context) {
return {
CallExpression: function (node) {
if (node.callee.name === "eval") {
context.report(node, "eval sucks.");
}
},
};
},
};
28 changes: 18 additions & 10 deletions tests/fixtures/testers/rule-tester/no-invalid-args.js
Expand Up @@ -3,20 +3,28 @@
* @author Mathias Schreck
*/

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
"use strict";

var config = context.options[0];
module.exports = {
meta: {
fixable: "code",
schema: [{
type: "boolean"
}]
},
create(context) {
var config = context.options[0];

return {
"Program": function(node) {
if (config === true) {
context.report(node, "Invalid args");
return {
"Program": function(node) {
if (config === true) {
context.report(node, "Invalid args");
}
}
}
};
};
}
};
34 changes: 17 additions & 17 deletions tests/fixtures/testers/rule-tester/no-invalid-schema.js
Expand Up @@ -3,26 +3,26 @@
* @author Brandon Mills
*/

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
"use strict";

var config = context.options[0];

return {
"Program": function(node) {
if (config) {
context.report(node, "Expected nothing.");
module.exports = {
meta: {
type: "problem",
schema: [{
"enum": []
}]
},
create(context) {
return {
"Program": function(node) {
if (config) {
context.report(node, "Expected nothing.");
}
}
}
};
};
},
};

module.exports.schema = [
{
"enum": []
}
];
35 changes: 18 additions & 17 deletions tests/fixtures/testers/rule-tester/no-schema-violation.js
Expand Up @@ -3,26 +3,27 @@
* @author Brandon Mills
*/

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
"use strict";

var config = context.options[0];

return {
"Program": function(node) {
if (config && config !== "foo") {
context.report(node, "Expected foo.");
module.exports = {
meta: {
type: "problem",
schema: [{
"enum": ["foo"]
}]
},
create(context) {
const config = context.options[0];
return {
"Program": function(node) {
if (config && config !== "foo") {
context.report(node, "Expected foo.");
}
}
}
};
};
},
};

module.exports.schema = [
{
"enum": ["foo"]
}
];
24 changes: 15 additions & 9 deletions tests/fixtures/testers/rule-tester/no-test-filename
Expand Up @@ -3,18 +3,24 @@
* @author Stefan Lau
*/

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
"use strict";

return {
"Program": function(node) {
if (context.getFilename() === '<input>') {
context.report(node, "Filename test was not defined.");
module.exports = {
meta: {
fixable: "code",
schema: []
},
create(context) {
return {
"Program": function(node) {
if (context.getFilename() === '<input>') {
context.report(node, "Filename test was not defined.");
}
}
}
};
};
}
};
34 changes: 20 additions & 14 deletions tests/fixtures/testers/rule-tester/no-test-global.js
Expand Up @@ -7,21 +7,27 @@
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
"use strict";
"use strict";

return {
"Program": function(node) {
var globals = context.getScope().variables.map(function (variable) {
return variable.name;
});
module.exports = {
meta: {
type: "problem",
schema: [],
},
create(context) {
return {
"Program": function(node) {
var globals = context.getScope().variables.map(function (variable) {
return variable.name;
});

if (globals.indexOf("test") === -1) {
context.report(node, "Global variable test was not defined.");
if (globals.indexOf("test") === -1) {
context.report(node, "Global variable test was not defined.");
}
if (globals.indexOf("foo") !== -1) {
context.report(node, "Global variable foo should not be used.");
}
}
if (globals.indexOf("foo") !== -1) {
context.report(node, "Global variable foo should not be used.");
}
}
};
};
},
};

0 comments on commit 1a723c1

Please sign in to comment.