Skip to content

Commit

Permalink
Create rule and add as warning
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Feb 5, 2021
1 parent 643d5c4 commit ca1cea1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
13 changes: 1 addition & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = {
},
],
'@wordpress/no-unsafe-wp-apis': 'off',
'@wordpress/no-store-string-literals': 'warn',
'import/default': 'error',
'import/named': 'error',
'no-restricted-imports': [
Expand Down Expand Up @@ -153,18 +154,6 @@ module.exports = {
message:
'Avoid truthy checks on length property rendering, as zero length is rendered verbatim.',
},
{
selector:
'CallExpression[callee.name=/^(select|dispatch|useDispatch)$/][arguments.0.type="Literal"]',
message:
'Do not use string literals for accessing stores ; import the store and use the store object instead',
},
{
selector:
'CallExpression[callee.object.name=/^controls|registry$/][callee.property.name=/^(select|dispatch)$/][arguments.0.type="Literal"]',
message:
'Do not use string literals for accessing stores ; import the store and use the store object instead',
},
],
},
overrides: [
Expand Down
30 changes: 30 additions & 0 deletions packages/eslint-plugin/rules/no-store-string-literals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
meta: {
type: 'problem',
schema: [],
messages: {
doNotUseStringLiteral:
'Do not use string literals for accessing stores ; import the store and use the store object or store name constant instead',
},
},
create( context ) {
return {
'CallExpression[callee.name=/^(select|dispatch|useDispatch)$/][arguments.0.type="Literal"]'(
node
) {
context.report( {
node,
messageId: 'doNotUseStringLiteral',
} );
},
'CallExpression[callee.object.name=/^controls|registry$/][callee.property.name=/^(select|dispatch|resolveSelect)$/][arguments.0.type="Literal"]'(
node
) {
context.report( {
node,
messageId: 'doNotUseStringLiteral',
} );
},
};
},
};

0 comments on commit ca1cea1

Please sign in to comment.