Closed artalar closed 4 weeks ago
cc @pivaszbs
Pls also note there might be usage like so:
class SomeService {
private someAtom= atom('smth', SomeService.name + '.someAtom')
}
@BANOnotIT thx, added
@krulod what is the progress of this task?
Here is how it can look like with 🐊Putout: https://putout.cloudcmd.io/#/gist/12b7eb96e17213067d22849890dbda3a/44d2c775f1d8872b62162ac76a5b3c762dbe92d2
export const report = () => `Add argument to ‘atom'`;
export const match = ({__a}) => ({
'const __a = atom(__b)': ({__a}, path) => {
return isIdentifier(__a);
}
});
export const replace = () => ({
'const __a = atom(__b)': addName('const __a = reatomComponent(__b, "__a_name")'),
'const __a = action(() => {})': addName('const __a = action(() => {}, "__a_name")'),
'const __a = {__b: atom(0, __c)}': addName('const __a = {__b: atom(0, "__a_name.__b_name")}'),
'const __a = {__b: action(__c, __d)}': addName('const __a = {__b: action(__c, "__a_name.__b_name")}'),
});
const addName = (template) => ({__a, __b, path}) => {
console.log(__a.name, __b?.name);
return template
.replace('__a_name', __a.name)
.replace('__b_name', __b?.name);
};
Input:
import { action, atom } from "@reatom/framework";
const some = atom(0);
const doSome = action(() => {});
const obj1 = {some: atom(0, 'dodge.${name}')}
const obj2 = {doSome: action(() => {}, 'obj.doRun')}
const domain = 'domain';
const obj3 = {
some: atom(0, `${domain}.dodge.some`)
};
const obj4 = {
some: atom(0, `${domain}WAT.dodge.some`)
};
Output:
import {action, atom} from '@reatom/framework';
const some = reatomComponent(0, 'some');
const doSome = action(() => {}, 'doSome');
const obj1 = {
some: atom(0, 'obj1.some'),
};
const obj2 = {
doSome: action(() => {}, 'obj2.doSome'),
};
const domain = 'domain';
const obj3 = {
some: atom(0, 'obj3.some'),
};
const obj4 = {
some: atom(0, 'obj4.some'),
};
We should support a couple additional cases: private prefix (
_
), domain chain (some.atomName
), object keys as the name for property atom. The fix suggestions should respect it and use it. Here is a list of currently invalid tests: unit-naming-rule.test.ts in eslint-next branch.Here is an article about writing an ESLint plugin: https://dev.to/xavescor/eslint-plugin-what-was-missed-in-the-doc-fmg
These changes may require a huge refactoring, it would be nice to support eslint@9 as well (cc https://github.com/artalar/reatom/issues/857).
Here is a helpful tools which you can use: https://github.com/coderaiser/putout/issues/210, https://github.com/artalar/reatom/issues/523#issuecomment-2192042677.
Upvote & Fund