Skip to content

Commit

Permalink
#36 Rule tested
Browse files Browse the repository at this point in the history
  • Loading branch information
gkouziik committed Sep 17, 2019
1 parent 498cac3 commit d793b38
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 68 deletions.
70 changes: 35 additions & 35 deletions lib/rules/detect-runinthiscontext-method-in-nodes-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
* @fileoverview detect vm.runInThisContext() method in nodes vm
* @author Gkouziik
*/
"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
'use strict'

module.exports = {
meta: {
docs: {
description: "detect vm.runInThisContext() method in nodes vm",
category: "Fill me in",
recommended: false
},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
meta: {
type: 'suggestion',
messages: {
msg: 'detect runInThisContext() with non Literal argument'
},

create: function(context) {

// variables should be defined here

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------

// any helper functions should go here or else delete this section

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------

return {

// give me methods

};
docs: {
description: 'detect vm.runInThisContext() method in nodes vm with non Literal argument',
category: 'Possible Errors',
recommended: false
},
fixable: 'null'
},

create: function (context) {
return {
'CallExpression': function (node) {
if (node.callee.hasOwnProperty('property')) {
if (node.callee.property.hasOwnProperty('name')) {
if (node.callee.property.name === 'runInThisContext') {
if (node.arguments.length > 0 && node.arguments[0].type !== 'Literal') {
context.report({
node: node,
messageId: 'msg',
loc: {
start: node.arguments[0].loc.start,
end: node.arguments[0].loc.end
}
})
}
}
}
}
}
}
};
}
}
61 changes: 28 additions & 33 deletions tests/lib/rules/detect-runinthiscontext-method-in-nodes-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,31 @@
* @fileoverview detect vm.runInThisContext() method in nodes vm
* @author Gkouziik
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var rule = require("../../../lib/rules/detect-runinthiscontext-method-in-nodes-vm"),

RuleTester = require("eslint").RuleTester;


//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

var ruleTester = new RuleTester();
ruleTester.run("detect-runinthiscontext-method-in-nodes-vm", rule, {

valid: [

// give me some code that won't trigger a warning
],

invalid: [
{
code: "",
errors: [{
message: "Fill me in.",
type: "Me too"
}]
}
]
});
'use strict'

var rule = require('../../../lib/rules/detect-runinthiscontext-method-in-nodes-vm')

var RuleTester = require('eslint').RuleTester
const ERROR_MSG = 'detect runInThisContext() with non Literal argument'
const valid = 'vm.runInThisContext("foo");'
const invalid = 'vm.runInThisContext(foo);'

var ruleTester = new RuleTester()
ruleTester.run('detect-runinthiscontext-method-in-nodes-vm', rule, {

valid: [
{
code: valid
}

],

invalid: [
{
code: invalid,
errors: [{
message: ERROR_MSG
}]
}
]
})

0 comments on commit d793b38

Please sign in to comment.