website refactor
This commit is contained in:
36
apps/website/eslint-rules/component-no-data-manipulation.js
Normal file
36
apps/website/eslint-rules/component-no-data-manipulation.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* ESLint rule: Components must not manipulate data
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Forbid data manipulation in components',
|
||||
category: 'Components',
|
||||
},
|
||||
messages: {
|
||||
message: 'Components must not manipulate data - see apps/website/lib/contracts/view-data/ViewData.ts',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
const filename = context.getFilename();
|
||||
if (filename.includes('/components/')) {
|
||||
// Check for mutation methods
|
||||
if (node.callee.type === 'MemberExpression') {
|
||||
const property = node.callee.property;
|
||||
if (property.type === 'Identifier' &&
|
||||
['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse', 'assign'].includes(property.name)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'message',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user