Skip to content

Commit

Permalink
refactor(eslint-plugin): address issues
Browse files Browse the repository at this point in the history
  • Loading branch information
krulod committed Sep 12, 2024
1 parent d49ece0 commit f740536
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Here is an example of React + TypeScript + Prettier config with Reatom.
"prettier/prettier": "error"
},
"settings": {
"atomSuffix": "Atom"
"atomPostfix": "Atom"
}
}
```
Expand Down Expand Up @@ -93,7 +93,7 @@ When creating units within `reatom*`-named factory functions, you can also speci

```ts
const reatomFood = (config: { name: string; calories: number; fat: number; carbs: number; protein: number }) => {
const { name } = config.name
const { name } = config
const calories = atom(config.calories, `Food.calories`)
const fat = atom(config.fat, `Food.fat`)
const carbs = atom(config.carbs, `Food.carbs`)
Expand All @@ -106,7 +106,7 @@ If a factory function defines a parameter or a variable named `name`, names of u

```ts
const reatomFood = (config: { name: string; calories: number; fat: number; carbs: number; protein: number }) => {
const { name } = config.name
const { name } = config
const calories = atom(config.calories, `${name}.calories`)
const fat = atom(config.fat, `${name}.fat`)
const carbs = atom(config.carbs, `${name}.carbs`)
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/rules/unit-naming-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ tester.run('unit-naming-rule', unitNamingRule, {
errors: [{ message: /domain must be derived from/ }],
output: `function reatomSome({name}) { const field = atom(0, \`\${name}.field\`); }`,
},
{
code: `function reatomSome(config) { const {name} = config; const field = atom(0, 'Some.field'); }`,
errors: [{ message: /domain must be derived from/ }],
output: `function reatomSome(config) { const {name} = config; const field = atom(0, \`\${name}.field\`); }`,
},
],
})
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/unit-naming-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const unitNamingRule: Rule.RuleModule = {
domainScopes.push({ is: 'static', name: node.id.name.replace('reatom', '') })
} else domainScopes.push(null)
},
[`:function:exit`](node: estree.Function) {
[`:function:exit`]() {
domainScopes.pop()
},
[`CallExpression[callee.name=${reatomFactoryPattern}]`](node: estree.CallExpression) {
Expand Down
29 changes: 0 additions & 29 deletions packages/eslint-plugin/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,6 @@ import type * as estree from 'estree'
export const reatomFactoryList = ['atom', 'action', 'reaction'] as const
export const reatomFactoryPattern = new RegExp(`^(reatom\\w+|${reatomFactoryList.join('|')})$`)

// export const createImportMap = (packagePrefix: string) => {
// const imported = new Map<string, string>()
// const local = new Map<string, string>()

// const onImportNode = (node: estree.ImportDeclaration) => {
// const source = node.source.value
// if (typeof source !== 'string' || !source.startsWith(packagePrefix)) {
// return
// }

// for (const spec of node.specifiers) {
// if (spec.type === 'ImportSpecifier') {
// onImportSpec(spec)
// }
// }
// }

// const onImportSpec = (spec: estree.ImportSpecifier) => {
// imported.set(spec.imported.name, spec.local.name)
// local.set(spec.local.name, spec.imported.name)
// }

// return {
// onImportNode,
// imported: imported as ReadonlyMap<string, string>,
// local: local as ReadonlyMap<string, string>,
// }
// }

export const patternNames = (pattern: estree.Pattern): estree.Identifier[] => {
if (pattern.type === 'AssignmentPattern') {
return patternNames(pattern.left)
Expand Down

0 comments on commit f740536

Please sign in to comment.