@jsenv/eslint-config-relax 1.1.0 → 1.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/eslint-config-relax",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A pleaseant ESLint configuration for any project",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,6 +33,7 @@
33
33
  "@babel/eslint-parser": "7.25.1",
34
34
  "globals": "15.9.0",
35
35
  "@jsenv/eslint-import-resolver": "8.2.0",
36
+ "@jsenv/urls": "2.5.2",
36
37
  "eslint-plugin-import-x": "3.1.0",
37
38
  "eslint-plugin-html": "8.1.1",
38
39
  "eslint-plugin-react": "7.35.0",
package/readme.md CHANGED
@@ -1,3 +1,36 @@
1
1
  # eslint-config-relax
2
2
 
3
3
  [![npm package](https://img.shields.io/npm/v/@jsenv/eslint-config-relax.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/eslint-config-relax)
4
+
5
+ Two things:
6
+
7
+ 1. ESLint should bother me only for important things
8
+ 2. Share ESLint configuration for different types of project
9
+
10
+ ## Usage
11
+
12
+ ```console
13
+ npm i --save-dev @jsenv/eslint-config-relax
14
+ ```
15
+
16
+ **eslint.config.js**
17
+
18
+ ```js
19
+ import { eslintConfigRelax } from "@jsenv/eslint-config-relax";
20
+
21
+ export default eslintConfigRelax({
22
+ rootDirectoryUrl: new URL("./", import.meta.url),
23
+ browserDirectoryUrl: new URL("./src/", import.meta.url), // optional
24
+ });
25
+ ```
26
+
27
+ ## Best parts
28
+
29
+ - No need to configure ESLint; it is hard to do correctly
30
+ - Freedom in the code; rules coercing you to code in a certain way are disabled
31
+ - Import resolution works; The whole node esm resolution algorith is implemented
32
+
33
+ ## To know
34
+
35
+ - No support for TypeScript (it's planned)
36
+ - Not compatible with ESLint < 8
@@ -1,4 +1,5 @@
1
1
  import babelParser from "@babel/eslint-parser";
2
+ import { urlToRelativeUrl } from "@jsenv/urls";
2
3
  import html from "eslint-plugin-html";
3
4
  import pluginImportX from "eslint-plugin-import-x";
4
5
  import reactPlugin from "eslint-plugin-react";
@@ -18,9 +19,18 @@ const patternForEachExtension = (pattern, extensions) => {
18
19
  );
19
20
  };
20
21
 
22
+ /**
23
+ * Return an ESLint flat config
24
+ * @param {Object} parameters
25
+ * @param {string|url} parameters.rootDirectoryUrl
26
+ * Directory containing the eslint config file and likely your package.json
27
+ * @param {string|url} [parameters.webDirectoryUrl]
28
+ * Directory leading to files that will be executed by a web browser
29
+ * @return {Array} Array of ESLint config objects
30
+ */
21
31
  export const eslintConfigRelax = ({
22
32
  rootDirectoryUrl,
23
- type = "browser",
33
+ browserDirectoryUrl,
24
34
  prettier,
25
35
  prettierSortImport,
26
36
  jsxPragmaAuto = false,
@@ -29,7 +39,7 @@ export const eslintConfigRelax = ({
29
39
  browserFiles = [],
30
40
  browserAndNodeFiles = [],
31
41
  } = {}) => {
32
- const packageJsonFileUrl = new URL("./package.json", import.meta.url);
42
+ const packageJsonFileUrl = new URL("./package.json", rootDirectoryUrl);
33
43
  let packageObject = {};
34
44
  try {
35
45
  const packageBuffer = readFileSync(packageJsonFileUrl);
@@ -40,8 +50,8 @@ export const eslintConfigRelax = ({
40
50
  if (devDependencies.prettier || packageObject.prettier) {
41
51
  prettier = true;
42
52
  } else if (
43
- existsSync(new URL("./.prettierrc.yml", import.meta.url)) ||
44
- existsSync(new URL(".prettierignore", import.meta.url))
53
+ existsSync(new URL("./.prettierrc.yml", rootDirectoryUrl)) ||
54
+ existsSync(new URL(".prettierignore", rootDirectoryUrl))
45
55
  ) {
46
56
  prettier = true;
47
57
  }
@@ -52,15 +62,17 @@ export const eslintConfigRelax = ({
52
62
  }
53
63
  }
54
64
 
55
- const isBrowser = type === "browser";
56
65
  const browserExtensions = [".js", ".jsx"];
57
66
  browserFiles = [
58
67
  "**/*.html",
59
68
  ...patternForEachExtension("**/client/**/*[extension]", browserExtensions),
60
69
  ...patternForEachExtension("**/www/**/*[extension]", browserExtensions),
61
70
  ...patternForEachExtension("**/browser/**/*[extension]", browserExtensions),
62
- ...(isBrowser
63
- ? patternForEachExtension("src/**/*[extension]", browserExtensions)
71
+ ...(browserDirectoryUrl
72
+ ? patternForEachExtension(
73
+ `${urlToRelativeUrl(browserDirectoryUrl, rootDirectoryUrl)}/**/*[extension]`,
74
+ browserExtensions,
75
+ )
64
76
  : []),
65
77
  ...browserFiles,
66
78
  ];
@@ -191,11 +203,7 @@ export const eslintConfigRelax = ({
191
203
  settings: {
192
204
  "import-x/resolver": {
193
205
  "@jsenv/eslint-import-resolver": {
194
- rootDirectoryUrl: String(
195
- isBrowser
196
- ? new URL("./src/", rootDirectoryUrl)
197
- : rootDirectoryUrl,
198
- ),
206
+ rootDirectoryUrl: browserDirectoryUrl || rootDirectoryUrl,
199
207
  packageConditions: ["browser", "import"],
200
208
  logLevel: importResolutionLogLevel,
201
209
  },