saleor-dashboard/lint/rules/named-styles.js

37 lines
964 B
JavaScript
Raw Normal View History

module.exports = {
create: context => ({
CallExpression: (codePath, node) => {
if (
["makeStyles", "withStyles"].includes(codePath.callee.name) &&
codePath.arguments.length < 2
) {
context.report({
2019-12-03 15:23:42 +00:00
fix: fixer =>
fixer.insertTextAfter(
codePath.arguments[0],
`,{ name: "${context
.getFilename()
.split("/")
.slice(-1)[0]
.replace(/\..+/, "")}" }`
),
loc: codePath.callee.loc,
messageId:
codePath.callee.name === "makeStyles"
? "expectedNameHook"
: "expectedNameHoc",
node
});
}
}
}),
meta: {
2019-12-03 15:23:42 +00:00
fixable: "code",
messages: {
expectedNameHoc: 'withStyles hook should have "name" property.',
expectedNameHook: 'makeStyles hook should have "name" property.'
},
type: "problem"
}
};