@byscott-io/eslint-config 0.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.
Files changed (3) hide show
  1. package/README.md +62 -0
  2. package/index.js +92 -0
  3. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @byscott-io/eslint-config
2
+
3
+ Shared ESLint **flat-config** preset for the byscott-io fleet (React + hooks).
4
+
5
+ One source of truth for eslint + plugin versions and house rules, so upgrades are
6
+ a single-package bump instead of every repo drifting on its own config. Requires
7
+ ESLint v9+ (flat config).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ yarn add -D eslint @byscott-io/eslint-config
13
+ ```
14
+
15
+ The preset brings its own plugins (`eslint-plugin-react`, `eslint-plugin-react-hooks`,
16
+ `@eslint/js`, `globals`) — you only need `eslint` itself.
17
+
18
+ ## Use
19
+
20
+ Create `eslint.config.js` at the repo root:
21
+
22
+ ```js
23
+ import byscott from "@byscott-io/eslint-config";
24
+
25
+ export default byscott();
26
+ ```
27
+
28
+ - Default globs: `src/**/*.{js,jsx}` and `app/javascript/**/*.{js,jsx}`.
29
+ - Override the source globs:
30
+
31
+ ```js
32
+ export default byscott({ files: ["app/javascript/**/*.{js,jsx}"] });
33
+ ```
34
+
35
+ - Add repo-specific ignores (appended to the fleet defaults):
36
+
37
+ ```js
38
+ export default byscott({ ignores: ["app/javascript/legacy/**"] });
39
+ ```
40
+
41
+ - Mark Node/server files so `process` / `require` / `__dirname` aren't reported
42
+ as undefined (globs must be a subset of the linted files):
43
+
44
+ ```js
45
+ export default byscott({ node: ["**/server.js", "packages/**/src/store.js"] });
46
+ ```
47
+
48
+ - Extend or override — the return value is a plain flat-config array:
49
+
50
+ ```js
51
+ export default [
52
+ ...byscott(),
53
+ { rules: { "no-console": "off" } }
54
+ ];
55
+ ```
56
+
57
+ ## What it enforces
58
+
59
+ `@eslint/js` recommended + house style (`no-var`, `prefer-const`, `no-unused-vars`
60
+ with `^_` escape, `no-console` as a warning) + React and React-Hooks rules
61
+ (`rules-of-hooks` error, `exhaustive-deps` warn; `prop-types` and
62
+ `react-in-jsx-scope` off for the modern JSX runtime).
package/index.js ADDED
@@ -0,0 +1,92 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+ import reactPlugin from "eslint-plugin-react";
4
+ import reactHooks from "eslint-plugin-react-hooks";
5
+
6
+ // Fleet-wide ESLint flat-config preset (React + hooks). One source of truth so
7
+ // eslint + plugin versions and house rules are a single-package bump, not ~15
8
+ // repos drifting. Extracted from corebyscott's proven v10 + flat-config setup.
9
+ //
10
+ // Usage in a consuming repo's eslint.config.js:
11
+ //
12
+ // import byscott from "@byscott-io/eslint-config";
13
+ // export default byscott(); // default globs
14
+ // export default byscott({ files: ["app/javascript/**/*.{js,jsx}"] });
15
+ // export default byscott({ ignores: ["app/javascript/legacy/**"] });
16
+ // export default byscott({ node: ["**/server.js", "packages/**/src/*.js"] }); // node/server files
17
+
18
+ // Source globs most fleet repos use: `src/` (packages) or `app/javascript/`
19
+ // (Rails apps). Override per repo when the layout differs.
20
+ export const DEFAULT_FILES = ["src/**/*.{js,jsx}", "app/javascript/**/*.{js,jsx}"];
21
+
22
+ export const DEFAULT_IGNORES = [
23
+ "node_modules/**",
24
+ "dist/**",
25
+ "app/assets/builds/**",
26
+ "public/**",
27
+ "vendor/**",
28
+ "coverage/**",
29
+ "cypress/videos/**",
30
+ "cypress/screenshots/**"
31
+ ];
32
+
33
+ // Returns a flat-config array. `files` scopes every rule set (including the JS
34
+ // recommended base) so stray root scripts / config files aren't linted; `ignores`
35
+ // is appended to the fleet defaults; `node` is a list of globs (a subset of the
36
+ // linted files, e.g. server/build scripts) that also get Node globals so
37
+ // `process`/`require`/`__dirname` aren't reported as undefined.
38
+ export default function byscottReact({ files = DEFAULT_FILES, ignores = [], node = [] } = {}) {
39
+ const config = [
40
+ { ...js.configs.recommended, files },
41
+ {
42
+ files,
43
+ languageOptions: {
44
+ ecmaVersion: 2022,
45
+ sourceType: "module",
46
+ globals: {
47
+ ...globals.browser,
48
+ ...globals.es2021
49
+ },
50
+ parserOptions: {
51
+ ecmaFeatures: { jsx: true }
52
+ }
53
+ },
54
+ plugins: {
55
+ react: reactPlugin,
56
+ "react-hooks": reactHooks
57
+ },
58
+ rules: {
59
+ // House style
60
+ "no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" }],
61
+ "no-console": "warn",
62
+ "prefer-const": "error",
63
+ "no-var": "error",
64
+
65
+ // React
66
+ "react/jsx-uses-react": "error",
67
+ "react/jsx-uses-vars": "error",
68
+ "react/prop-types": "off",
69
+ "react/react-in-jsx-scope": "off",
70
+
71
+ // React Hooks
72
+ "react-hooks/rules-of-hooks": "error",
73
+ "react-hooks/exhaustive-deps": "warn"
74
+ },
75
+ settings: {
76
+ react: { version: "detect" }
77
+ }
78
+ }
79
+ ];
80
+
81
+ // Node/server files: add Node globals on top so process/require/__dirname etc.
82
+ // aren't flagged as undefined.
83
+ if (node.length > 0) {
84
+ config.push({
85
+ files: node,
86
+ languageOptions: { globals: { ...globals.node } }
87
+ });
88
+ }
89
+
90
+ config.push({ ignores: [ ...DEFAULT_IGNORES, ...ignores ] });
91
+ return config;
92
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@byscott-io/eslint-config",
3
+ "version": "0.1.0",
4
+ "description": "Shared ESLint flat-config preset for the byscott-io fleet (React + hooks).",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "README.md"
13
+ ],
14
+ "publishConfig": {
15
+ "registry": "https://npm.pkg.github.com"
16
+ },
17
+ "peerDependencies": {
18
+ "eslint": ">=9"
19
+ },
20
+ "dependencies": {
21
+ "@eslint/js": "^9.39.2",
22
+ "eslint-plugin-react": "^7.34.0",
23
+ "eslint-plugin-react-hooks": "^7.1.1",
24
+ "globals": "^17.10.0"
25
+ }
26
+ }