Add basic eslint project with working logic

This commit is contained in:
Abhas
2018-09-21 14:29:40 +05:30
commit 51af1997aa
8 changed files with 1662 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* @fileoverview While using CSS Modules, disallow using (non-conditional / string) classNames in a JSX tag if it already has a styleName
* @author Abhas Bhattacharya
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var requireIndex = require("requireindex");
//------------------------------------------------------------------------------
// Plugin Definition
//------------------------------------------------------------------------------
// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + "/rules");
+51
View File
@@ -0,0 +1,51 @@
/**
* @fileoverview Disallow string className alongwith styleName in the same JSX tag
* @author Abhas Bhattacharya
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const reportText = "Do not use className alongwith styleName in same JSX tag. \nstyleName should compose from the className";
module.exports = {
meta: {
docs: {
description: "Disallow string className alongwith styleName in the same JSX tag",
category: "Fill me in",
recommended: false
},
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 {
"JSXOpeningElement": function (node) {
const hasClassNameWithoutExpr = node.attributes.some((attr) => attr.name.name === "className" && (attr.value === null || attr.value.type !== 'JSXExpressionContainer'))
const hasStyleName = node.attributes.some((attr) => attr.name.name === "styleName");
if (hasClassNameWithoutExpr && hasStyleName) {
context.report(node, reportText);
}
}
};
}
};