@dartess/eslint-plugin 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  [//]: # (https://keepachangelog.com/en/1.1.0/)
4
4
 
5
+ ## [0.8.1] - 2026-01-24
6
+
7
+ - fix `mobx-require-observer`: now it doesn't lose generics
8
+ - fix `mobx-require-observer`: now it respects directives like `'use client'`
9
+
5
10
  ## [0.8.0] - 2026-01-22
6
11
 
7
12
  - All recommended warnings are converted to errors because warnings are useless.
package/README.md CHANGED
@@ -23,7 +23,7 @@ All of it pinched with extra configs, setups and extra rules. Just take it and u
23
23
 
24
24
  ### Notes
25
25
 
26
- 1. The package is intended for use with TypeScript (it'll be useful for plain JS, but it hasn't been weel-tested).
26
+ 1. The package is intended for use with TypeScript (it'll be useful for plain JS, but it hasn't been well-tested).
27
27
 
28
28
  2. The package is intended for use only with the `flat` eslint config.
29
29
 
@@ -1,4 +1,4 @@
1
- import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
1
+ import { ESLintUtils, AST_NODE_TYPES, } from '@typescript-eslint/utils';
2
2
  function isCustomHook(fn) {
3
3
  if (fn.type === AST_NODE_TYPES.FunctionDeclaration && fn.id?.name.startsWith('use')) {
4
4
  return true;
@@ -13,6 +13,29 @@ function isCustomHook(fn) {
13
13
  }
14
14
  return false;
15
15
  }
16
+ function getTypeParamsText(fn, sourceCode) {
17
+ return fn.typeParameters ? sourceCode.getText(fn.typeParameters) : '';
18
+ }
19
+ function getObserverImportAnchor(program) {
20
+ const firstImport = program.body.find(n => n.type === AST_NODE_TYPES.ImportDeclaration);
21
+ if (firstImport) {
22
+ return { anchor: firstImport, method: 'insertTextBefore' };
23
+ }
24
+ let lastPrologue = null;
25
+ for (const node of program.body) {
26
+ if (node.type === AST_NODE_TYPES.ExpressionStatement &&
27
+ node.expression.type === AST_NODE_TYPES.Literal &&
28
+ typeof node.expression.value === 'string') {
29
+ lastPrologue = node;
30
+ continue;
31
+ }
32
+ break;
33
+ }
34
+ if (lastPrologue) {
35
+ return { anchor: lastPrologue, method: 'insertTextAfter' };
36
+ }
37
+ return { anchor: program.body[0], method: 'insertTextBefore' };
38
+ }
16
39
  export default ESLintUtils.RuleCreator(() => '')({
17
40
  name: 'mobx-require-observer',
18
41
  meta: {
@@ -97,7 +120,10 @@ export default ESLintUtils.RuleCreator(() => '')({
97
120
  fix(fixer) {
98
121
  const fixes = [];
99
122
  if (!hasObserverImport) {
100
- fixes.push(fixer.insertTextBefore(program.body[0], "import { observer } from 'mobx-react-lite';\n"));
123
+ const { anchor, method } = getObserverImportAnchor(program);
124
+ const nBefore = method === 'insertTextAfter' ? '\n' : '';
125
+ const nAfter = method === 'insertTextBefore' ? '\n' : '';
126
+ fixes.push(fixer[method](anchor, `${nBefore}import { observer } from 'mobx-react-lite';${nAfter}`));
101
127
  }
102
128
  const paramsText = fn.params.map(p => sourceCode.getText(p)).join(', ');
103
129
  const bodyText = sourceCode.getText(fn.body);
@@ -117,7 +143,8 @@ export default ESLintUtils.RuleCreator(() => '')({
117
143
  const id = fn.parent.id;
118
144
  const { name } = id;
119
145
  const isExport = exportDecl?.type === AST_NODE_TYPES.ExportNamedDeclaration;
120
- const funcExpression = `function ${name}(${paramsText}) ${bodyText}`;
146
+ const typeParamsText = getTypeParamsText(fn, sourceCode);
147
+ const funcExpression = `function ${name}${typeParamsText}(${paramsText}) ${bodyText}`;
121
148
  const replacementNodeText = `${isExport ? 'export ' : ''}const ${name} = observer(${funcExpression});`;
122
149
  fixes.push(fixer.replaceText(exportDecl || varDecl, replacementNodeText));
123
150
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dartess/eslint-plugin",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "description": "A set of rules and configs for various TypeScript projects",
6
6
  "keywords": [
7
7
  "eslint",