Skip to content

Commit

Permalink
chore(eslint): add custom rule to disallow componentOnReady method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi authored Sep 15, 2022
1 parent 174c3b3 commit 8629dfa
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 220 deletions.
6 changes: 4 additions & 2 deletions core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"custom-rules"
],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
Expand All @@ -29,6 +30,7 @@ module.exports = {
],
"no-useless-catch": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-case-declarations": "off"
"no-case-declarations": "off",
"custom-rules/no-component-on-ready-method": "error"
}
};
5 changes: 5 additions & 0 deletions core/custom-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-component-on-ready-method': require('./no-component-on-ready-method.js')
}
}
23 changes: 23 additions & 0 deletions core/custom-rules/no-component-on-ready-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
meta: {
messages: {
noComponentOnReadyMethod: 'Using the componentOnReady method is not allowed. Use the componentOnReady helper utility in src/utils/helpers.ts instead.',
},
},
create(context) {
return {
CallExpression(node) {
/**
* We only want to exclude usages of componentOnReady().
* Checking for the existence of the componentOnReady method
* is a way of determining if we are in a lazy loaded build
* or custom elements build, so we want to allow that.
*/
const callee = node.callee;
if (callee.type === 'MemberExpression' && callee.property.name === 'componentOnReady') {
context.report({ node: node, messageId: 'noComponentOnReadyMethod' });
}
}
}
}
};
5 changes: 5 additions & 0 deletions core/custom-rules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "eslint-plugin-custom-rules",
"version": "1.0.0",
"main": "index.js"
}
Loading

0 comments on commit 8629dfa

Please sign in to comment.