@precisa-saude/eslint-config 1.0.3 → 1.1.0

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/base.js CHANGED
@@ -77,6 +77,13 @@ const base = [
77
77
  'no-throw-literal': 'error',
78
78
  'no-undef': 'off',
79
79
 
80
+ // Size limits — forcing decomposition before files/functions get
81
+ // unreadable. Thresholds are warns, not errors, so one-off
82
+ // offenders don't block landing. Data/mapping files should be
83
+ // ignored via `overrides` or per-repo `ignores`.
84
+ 'max-lines': ['warn', { max: 400, skipBlankLines: true, skipComments: true }],
85
+ 'max-lines-per-function': ['warn', { max: 300, skipBlankLines: true, skipComments: true }],
86
+
80
87
  'perfectionist/sort-interfaces': [
81
88
  'error',
82
89
  {
package/html.js ADDED
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ import html from '@html-eslint/eslint-plugin';
3
+
4
+ /**
5
+ * ESLint preset for HTML files.
6
+ *
7
+ * Applies `@html-eslint` rules to `**\/*.html` with sensible defaults.
8
+ * Separate from `base` because not every repo has HTML files and the
9
+ * plugin pulls in its own parser.
10
+ *
11
+ * Usage:
12
+ * import htmlConfig from '@precisa-saude/eslint-config/html';
13
+ * export default [...base, ...htmlConfig];
14
+ *
15
+ * If you need to tighten or relax rules, add another block after this
16
+ * one in your config array.
17
+ */
18
+ const htmlConfig = [
19
+ {
20
+ files: ['**/*.html'],
21
+ ignores: ['**/node_modules/**', '**/dist/**', '**/coverage/**'],
22
+ plugins: {
23
+ '@html-eslint': html,
24
+ },
25
+ languageOptions: {
26
+ parser: html.configs['flat/recommended'].languageOptions.parser,
27
+ },
28
+ rules: {
29
+ '@html-eslint/sort-attrs': 'error',
30
+ },
31
+ },
32
+ ];
33
+
34
+ export default htmlConfig;
@@ -0,0 +1,71 @@
1
+ // @ts-nocheck
2
+ import typescript from '@typescript-eslint/eslint-plugin';
3
+ import tsParser from '@typescript-eslint/parser';
4
+ import globals from 'globals';
5
+
6
+ import base from './base.js';
7
+
8
+ /**
9
+ * ESLint preset for Node.js backends (Express/Fastify/Hono/etc.).
10
+ *
11
+ * Extends `base` with:
12
+ * - Node globals (process, Buffer, __dirname, etc.)
13
+ * - `no-console: off` — backends legitimately log to stdout
14
+ * - Express-friendly `no-misused-promises` (async route handlers are
15
+ * void-returning by convention)
16
+ * - Relaxed type-safety warnings (external API surfaces pull in lots
17
+ * of `any`; turning these to errors is hostile on day one)
18
+ *
19
+ * File patterns match the ecosystem's backend conventions. Override
20
+ * `BACKEND_PATHS` if you have a non-standard layout.
21
+ *
22
+ * Usage:
23
+ * import nodeBackend from '@precisa-saude/eslint-config/node-backend';
24
+ * export default [...nodeBackend];
25
+ *
26
+ * Platform-specific rules (e.g. restricted imports for LGPD compliance)
27
+ * go in the consumer repo's eslint.config.js, not here.
28
+ */
29
+ export const BACKEND_PATHS = ['apps/api/**/*.ts', 'apps/server/**/*.ts', 'packages/api-*/**/*.ts'];
30
+
31
+ const nodeBackend = [
32
+ ...base,
33
+
34
+ {
35
+ files: BACKEND_PATHS,
36
+ languageOptions: {
37
+ parser: tsParser,
38
+ parserOptions: {
39
+ ecmaVersion: 2022,
40
+ sourceType: 'module',
41
+ project: true,
42
+ },
43
+ globals: {
44
+ ...globals.node,
45
+ ...globals.es2022,
46
+ },
47
+ },
48
+ plugins: {
49
+ '@typescript-eslint': typescript,
50
+ },
51
+ rules: {
52
+ 'no-console': 'off',
53
+
54
+ // Express route handlers are async but void-returning. The
55
+ // recommended rule has false positives here.
56
+ '@typescript-eslint/no-misused-promises': [
57
+ 'error',
58
+ { checksVoidReturn: { arguments: false } },
59
+ ],
60
+
61
+ // Backends pull types through lots of external API boundaries; full
62
+ // strictness on day one is hostile. Warn, don't error.
63
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
64
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
65
+ '@typescript-eslint/no-unsafe-argument': 'warn',
66
+ '@typescript-eslint/require-await': 'warn',
67
+ },
68
+ },
69
+ ];
70
+
71
+ export default nodeBackend;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@precisa-saude/eslint-config",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Shared flat ESLint config (9+/10) for Precisa Saúde repositories.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -21,16 +21,21 @@
21
21
  "exports": {
22
22
  ".": "./base.js",
23
23
  "./base": "./base.js",
24
- "./react": "./react.js"
24
+ "./react": "./react.js",
25
+ "./node-backend": "./node-backend.js",
26
+ "./html": "./html.js"
25
27
  },
26
28
  "main": "./base.js",
27
29
  "files": [
28
30
  "base.js",
29
31
  "react.js",
32
+ "node-backend.js",
33
+ "html.js",
30
34
  "README.md"
31
35
  ],
32
36
  "dependencies": {
33
37
  "@eslint/js": "^9.39.2",
38
+ "@html-eslint/eslint-plugin": "^0.52.1",
34
39
  "@typescript-eslint/eslint-plugin": "^8.57.2",
35
40
  "@typescript-eslint/parser": "^8.57.2",
36
41
  "eslint-config-prettier": "^9.1.2",
package/react.js CHANGED
@@ -16,22 +16,48 @@ import base from './base.js';
16
16
  * React ESLint flat config. Extends `base` with React, React Hooks, JSX a11y,
17
17
  * React Refresh, and better-tailwindcss rules.
18
18
  *
19
- * Usage:
20
- * import reactConfig from '@precisa-saude/eslint-config/react';
21
- * export default [
22
- * ...reactConfig,
23
- * {
24
- * settings: {
25
- * 'better-tailwindcss': { tailwindConfig: './tailwind.config.js' },
26
- * },
27
- * },
28
- * ];
19
+ * Two usage patterns:
20
+ *
21
+ * 1) Default-scoped (most repos): import as the default export; it uses
22
+ * `REACT_PATHS` covering apps/web, apps/landing, site, packages/ui.
23
+ *
24
+ * import reactConfig from '@precisa-saude/eslint-config/react';
25
+ * export default [...reactConfig];
26
+ *
27
+ * 2) Custom-scoped (repos with atypical layouts): import the `withFiles`
28
+ * factory and pass your own glob patterns. Use this when you need
29
+ * React rules to apply only to specific paths — typically because a
30
+ * Node/Express backend lives in a different directory that must not
31
+ * pick up React rules.
32
+ *
33
+ * import { withFiles } from '@precisa-saude/eslint-config/react';
34
+ * export default [
35
+ * ...withFiles(['apps/{web,landing}/**\/*.{ts,tsx}', 'packages/ui/**\/*.{ts,tsx}']),
36
+ * ];
37
+ */
38
+
39
+ // Default file patterns matching the ecosystem's React conventions:
40
+ // - Platform: apps/web, apps/landing, packages/ui
41
+ // - OSS repos with a site: site/
42
+ export const REACT_PATHS = [
43
+ 'apps/{web,landing}/**/*.{ts,tsx,jsx}',
44
+ 'site/**/*.{ts,tsx,jsx}',
45
+ 'packages/ui/**/*.{ts,tsx,jsx}',
46
+ ];
47
+
48
+ /**
49
+ * Build a React-rules block scoped to the given file globs. Returned as
50
+ * an array for spread-compatibility with base:
51
+ *
52
+ * [...base, ...withFiles([...paths])]
29
53
  */
30
- const reactConfig = [
31
- ...base,
54
+ export function withFiles(files) {
55
+ return [...base, buildReactBlock(files)];
56
+ }
32
57
 
33
- {
34
- files: ['**/*.{ts,tsx,jsx}'],
58
+ function buildReactBlock(files) {
59
+ return {
60
+ files,
35
61
  languageOptions: {
36
62
  parser: tsParser,
37
63
  parserOptions: {
@@ -99,7 +125,9 @@ const reactConfig = [
99
125
  },
100
126
  ],
101
127
  },
102
- },
103
- ];
128
+ };
129
+ }
130
+
131
+ const reactConfig = [...base, buildReactBlock(REACT_PATHS)];
104
132
 
105
133
  export default reactConfig;