Skip to content

Commit

Permalink
fix(eslint-plugin): fix eslint build #1027 (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
osovv authored Feb 3, 2025
1 parent e83c527 commit 8dd2669
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 13 additions & 5 deletions packages/eslint-plugin/src/rules/unit-naming-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ tester.run('unit-naming-rule', unitNamingRule, {
{
code: `function reatomSome() { const Atoms = { someAtom: atom(0, 'Some.Atoms.someAtom') } }`,
},
{
code: `function reatomSome({name}) { const Atoms = { someAtom: atom(0, \`\${name}.Atoms.someAtom\`) } }`
},
{
code: `const someFactory = reatomSome({ name: 'someFactory' })`
}
code: `function reatomSome({name}) { const Atoms = { someAtom: atom(0, \`\${name}.Atoms.someAtom\`) } }`,
},
{
code: `const someFactory = reatomSome({ name: 'someFactory' })`,
},
{
code: `function reatomSome(options, name) { const Atoms = { someAtom: atom(0, \`\${name}.Atoms.someAtom\`) } }`,
},
],
invalid: [
{
Expand Down Expand Up @@ -104,5 +107,10 @@ tester.run('unit-naming-rule', unitNamingRule, {
errors: [{ message: /domain must be derived from/ }],
output: `function reatomSome(config) { const {name} = config; const field = atom(0, \`\${name}.field\`); }`,
},
{
code: `function reatomSome(config, name) { const field = atom(0, 'Some.field'); }`,
errors: [{ message: /domain must be derived from/ }],
output: `function reatomSome(config, name) { const field = atom(0, \`\${name}.field\`); }`,
},
],
})
4 changes: 1 addition & 3 deletions packages/eslint-plugin/src/rules/unit-naming-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ export const unitNamingRule: Rule.RuleModule = {

let parsedName: Name | undefined
parseName: {
const targetNameNode = nameNode.type === 'Property' ? nameNode.value : nameNode

if (nameNode.type === 'Literal' && typeof nameNode.value === 'string') {
const matches = nameNode.value.match(/^(?:([\w$]+)\.)?(?:([\w$]+)\.)?(_)?([\w$]+)$/)
if (!matches) break parseName
Expand All @@ -174,7 +172,7 @@ export const unitNamingRule: Rule.RuleModule = {
const afterDomain = nameNode.quasis[1]!.value.raw.slice(1)
const [object, self] = afterDomain.includes('.') ? afterDomain.split('.') : [null, afterDomain]
const local = self.startsWith('_')
const unit = afterDomain.slice(local ? 1 : 0).split('.').at(-1)
const unit = afterDomain.slice(local ? 1 : 0).split('.').at(-1)!
parsedName = { domain: { is: 'dynamic', vary: domainVary }, object, local, unit }
}
}
Expand Down

0 comments on commit 8dd2669

Please sign in to comment.