Skip to content

Instantly share code, notes, and snippets.

@binjospookie
Created November 9, 2024 16:04
Show Gist options
  • Save binjospookie/317b3b32bd9671d08f6c6db053e579af to your computer and use it in GitHub Desktop.
Save binjospookie/317b3b32bd9671d08f6c6db053e579af to your computer and use it in GitHub Desktop.
storeName.mjs
import { ESLintUtils } from '@typescript-eslint/utils';
const createRule = ESLintUtils.RuleCreator(() => '');
export const storeNamingConvention = createRule({
name: 'store-naming-convention',
meta: {
type: 'layout',
docs: {
description: 'Enforce $ as a prefix or postfix for any store created by Effector methods',
recommended: true,
},
fixable: 'code',
schema: [],
},
defaultOptions: [],
create(context) {
const parserServices = ESLintUtils.getParserServices(context);
return {
'VariableDeclarator[parent.kind="const"][init.type="CallExpression"]'(node) {
const varName = node.id.name;
if (!varName || varName.startsWith('$')) return;
const type = parserServices.getTypeAtLocation(node);
// Store includes StoreWritable too
if (type.symbol && type.symbol.escapedName.includes('Store')) {
context.report({
node: node.id,
message: `Rename "${varName}" to $${varName}"`,
fix(fixer) {
return fixer.replaceText(node.id, `$${varName}`);
},
});
}
},
};
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment