var oHello = {};
var sHello = "Hello";
var hello = "World";
var aArray = [];
var iInt = 9;
var bBool = true;
var bool = true;
var fFunction = function(){};
var myfunction = function(){};
export default function (context) {
return {
VariableDeclarator: function (node) {
return
}
};
};
context.report({
node: node,
message: "Bad naming of variable"
});
export default function (context) {
return {
VariableDeclarator: function (node) {
if (node.id.name.charAt(0) === "s" && (node.init === null || node.init.type === "Literal" || node.init.type === "CallExpression")) {
return
} else if (node.id.name.charAt(0) === "f" && !(node.init === null || node.init.type === "FunctionExpression" || node.init.type ===
"CallExpression")) {
return;
} else if (node.id.name.charAt(0) === "o" &&
(node.init === null || node.init.type === "CallExpression" || node.init.type ===
"ObjectExpression")) {
return;
} else if (node.id.name.charAt(0) === "a" && (node.init === null || node.init.type === "CallExpression" || node.init.type ===
"ArrayExpression")) {
return;
} else if (node.id.name.charAt(0) === "i" && (node.init === null || node.init.type === "CallExpression" || node.init.type ===
"Literal")) {
return;
} else if (node.id.name.charAt(0) === "f" && (node.init === null || node.init.type === "FunctionExpression" || node.init.type ===
"Literal")) {
return;
} else {
context.report({
node: node,
message: "Bad naming of variable"
});
}
}
};
};
/**
* @fileoverview Ensure a proper naming convention for your variables
* @author Jakob Kjaer
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: "Ensure a proper naming convention for your variables",
category: "Error",
recommended: true
},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
},
create: function (context) {
// variables should be defined here
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
// any helper functions should go here or else delete this section
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
VariableDeclarator: function (node) {
if (node.id.name.charAt(0) === "s" && (node.init === null || node.init.type === "Literal" || node.init.type === "CallExpression")) {
return;
} else if (node.id.name.charAt(0) === "f" && !(node.init === null || node.init.type === "FunctionExpression" || node.init.type ===
"CallExpression")) {
return;
} else if (node.id.name.charAt(0) === "o" &&
(node.init === null || node.init.type === "CallExpression" || node.init.type ===
"ObjectExpression")) {
return;
} else if (node.id.name.charAt(0) === "a" && (node.init === null || node.init.type === "CallExpression" || node.init.type ===
"ArrayExpression")) {
return;
} else if (node.id.name.charAt(0) === "i" && (node.init === null || node.init.type === "CallExpression" || node.init.type ===
"Literal")) {
return;
} else if (node.id.name.charAt(0) === "f" && (node.init === null || node.init.type === "FunctionExpression" || node.init.type ===
"Literal")) {
return;
} else {
context.report({
node: node,
message: "Bad naming of variable"
});
}
}
};
}
};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |