@jsenv/eslint-config-relax 1.7.6 → 1.7.8
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/package.json +1 -1
- package/src/eslint_config_relax.js +66 -16
package/package.json
CHANGED
|
@@ -24,13 +24,49 @@ const patternForEachExtension = (pattern, extensions) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @param {
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
27
|
+
* Creates a comprehensive ESLint flat configuration with relaxed rules and automatic detection
|
|
28
|
+
* of project settings. Supports React/Preact, Prettier integration, browser/Node.js environments,
|
|
29
|
+
* and smart defaults based on your package.json dependencies.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} parameters - Configuration options
|
|
32
|
+
* @param {string|URL} parameters.rootDirectoryUrl - Directory containing the eslint config file and likely your package.json
|
|
33
|
+
* @param {string|URL} [parameters.browserDirectoryUrl] - Directory containing files that will be executed by a web browser (formerly webDirectoryUrl)
|
|
34
|
+
* @param {boolean} [parameters.prettier] - Enable Prettier integration. Auto-detected from package.json if not specified
|
|
35
|
+
* @param {boolean} [parameters.prettierSortImport] - Enable prettier-plugin-organize-imports integration. Auto-detected if not specified
|
|
36
|
+
* @param {boolean} [parameters.jsxPragmaAuto=false] - Disable react/react-in-jsx-scope rule for automatic JSX pragma
|
|
37
|
+
* @param {boolean} [parameters.preact] - Enable Preact-specific settings. Auto-detected from package.json if not specified
|
|
38
|
+
* @param {string} [parameters.reactVersion="detect"] - React version for eslint-plugin-react. Defaults to auto-detection
|
|
39
|
+
* @param {string} [parameters.reactVersionForPreact="19.2.0"] - React version to use when preact is detected
|
|
40
|
+
* @param {string} [parameters.importResolutionLogLevel] - Log level for import resolution debugging
|
|
41
|
+
* @param {string[]} [parameters.importResolutionDevConditions=[]] - Additional package.json conditions for import resolution in development
|
|
42
|
+
* @param {string[]} [parameters.browserFiles=[]] - Additional glob patterns for files that should use browser environment. Extends default patterns
|
|
43
|
+
* @param {string[]} [parameters.browserAndNodeFiles=[]] - Glob patterns for files that run in both browser and Node.js environments
|
|
44
|
+
*
|
|
45
|
+
* @returns {Array<Object>} Array of ESLint flat config objects configured with:
|
|
46
|
+
* - Relaxed rules optimized for development productivity
|
|
47
|
+
* - Automatic browser/Node.js environment detection
|
|
48
|
+
* - React/Preact JSX support with proper settings
|
|
49
|
+
* - Import resolution with package.json conditions
|
|
50
|
+
* - HTML file linting support
|
|
51
|
+
* - Prettier integration when detected
|
|
52
|
+
* - Smart ignores for common directories
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Basic usage with auto-detection
|
|
56
|
+
* import { eslintConfigRelax } from "@jsenv/eslint-config-relax";
|
|
57
|
+
* export default eslintConfigRelax({
|
|
58
|
+
* rootDirectoryUrl: import.meta.url
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // With custom browser directory and explicit settings
|
|
63
|
+
* export default eslintConfigRelax({
|
|
64
|
+
* rootDirectoryUrl: import.meta.url,
|
|
65
|
+
* browserDirectoryUrl: new URL("./src/client/", import.meta.url),
|
|
66
|
+
* prettier: true,
|
|
67
|
+
* preact: true,
|
|
68
|
+
* browserFiles: ["src/frontend/**"]
|
|
69
|
+
* });
|
|
34
70
|
*/
|
|
35
71
|
export const eslintConfigRelax = ({
|
|
36
72
|
rootDirectoryUrl,
|
|
@@ -41,6 +77,7 @@ export const eslintConfigRelax = ({
|
|
|
41
77
|
preact,
|
|
42
78
|
reactVersion = "detect",
|
|
43
79
|
reactVersionForPreact = "19.2.0",
|
|
80
|
+
importResolutionBrowserRootDirectoryUrl,
|
|
44
81
|
importResolutionLogLevel,
|
|
45
82
|
importResolutionDevConditions = [],
|
|
46
83
|
|
|
@@ -76,19 +113,29 @@ export const eslintConfigRelax = ({
|
|
|
76
113
|
}
|
|
77
114
|
|
|
78
115
|
const browserExtensions = [".js", ".jsx"];
|
|
79
|
-
|
|
116
|
+
const defaultBrowserFiles = [
|
|
80
117
|
"**/*.html",
|
|
81
118
|
...patternForEachExtension("**/client/**/*[extension]", browserExtensions),
|
|
82
119
|
...patternForEachExtension("**/www/**/*[extension]", browserExtensions),
|
|
83
120
|
...patternForEachExtension("**/browser/**/*[extension]", browserExtensions),
|
|
84
|
-
...(browserDirectoryUrl
|
|
85
|
-
? patternForEachExtension(
|
|
86
|
-
`${urlToRelativeUrl(browserDirectoryUrl, rootDirectoryUrl)}/**/*[extension]`,
|
|
87
|
-
browserExtensions,
|
|
88
|
-
)
|
|
89
|
-
: []),
|
|
90
|
-
...browserFiles,
|
|
91
121
|
];
|
|
122
|
+
if (browserDirectoryUrl) {
|
|
123
|
+
let browserDirectoryUrlString = String(browserDirectoryUrl);
|
|
124
|
+
if (!browserDirectoryUrlString.endsWith("/")) {
|
|
125
|
+
browserDirectoryUrlString += "/";
|
|
126
|
+
}
|
|
127
|
+
const relativeBrowserDir = urlToRelativeUrl(
|
|
128
|
+
browserDirectoryUrl,
|
|
129
|
+
rootDirectoryUrl,
|
|
130
|
+
);
|
|
131
|
+
defaultBrowserFiles.push(
|
|
132
|
+
...patternForEachExtension(
|
|
133
|
+
`${relativeBrowserDir}**/*[extension]`,
|
|
134
|
+
browserExtensions,
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
browserFiles = [...defaultBrowserFiles, ...browserFiles];
|
|
92
139
|
browserAndNodeFiles = [...browserAndNodeFiles];
|
|
93
140
|
const parserOptions = {
|
|
94
141
|
ecmaVersion: 2022,
|
|
@@ -274,7 +321,10 @@ export const eslintConfigRelax = ({
|
|
|
274
321
|
settings: {
|
|
275
322
|
"import-x/resolver": {
|
|
276
323
|
"@jsenv/eslint-import-resolver": {
|
|
277
|
-
rootDirectoryUrl:
|
|
324
|
+
rootDirectoryUrl:
|
|
325
|
+
importResolutionBrowserRootDirectoryUrl ||
|
|
326
|
+
browserDirectoryUrl ||
|
|
327
|
+
rootDirectoryUrl,
|
|
278
328
|
packageConditions: [
|
|
279
329
|
"browser",
|
|
280
330
|
"development",
|