@jsenv/eslint-config-relax 1.0.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/eslint-config-relax",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A pleaseant ESLint configuration for any project",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -30,6 +30,7 @@
30
30
  ],
31
31
  "scripts": {},
32
32
  "dependencies": {
33
+ "@babel/eslint-parser": "7.25.1",
33
34
  "globals": "15.9.0",
34
35
  "@jsenv/eslint-import-resolver": "8.2.0",
35
36
  "eslint-plugin-import-x": "3.1.0",
@@ -4,6 +4,7 @@ import pluginImportX from "eslint-plugin-import-x";
4
4
  import reactPlugin from "eslint-plugin-react";
5
5
  import * as regexpPlugin from "eslint-plugin-regexp";
6
6
  import globals from "globals";
7
+ import { existsSync, readFileSync } from "node:fs";
7
8
  import { explicitGlobals } from "./explicit_globals.js";
8
9
  import { rulesImportRelax } from "./rules_import_relax.js";
9
10
  import { rulesOffPrettier } from "./rules_off_prettier.js";
@@ -20,14 +21,37 @@ const patternForEachExtension = (pattern, extensions) => {
20
21
  export const eslintConfigRelax = ({
21
22
  rootDirectoryUrl,
22
23
  type = "browser",
23
- prettier = true, // ideally check presence of prettier config files, or in package.json dev deps
24
- prettierSortImport = false, // check presence in package deps
24
+ prettier,
25
+ prettierSortImport,
25
26
  jsxPragmaAuto = false,
26
27
  importResolutionLogLevel,
27
28
 
28
29
  browserFiles = [],
29
30
  browserAndNodeFiles = [],
30
31
  } = {}) => {
32
+ const packageJsonFileUrl = new URL("./package.json", import.meta.url);
33
+ let packageObject = {};
34
+ try {
35
+ const packageBuffer = readFileSync(packageJsonFileUrl);
36
+ packageObject = JSON.parse(String(packageBuffer));
37
+ } catch {}
38
+ const { devDependencies = {} } = packageObject;
39
+ if (prettier === undefined) {
40
+ if (devDependencies.prettier || packageObject.prettier) {
41
+ prettier = true;
42
+ } else if (
43
+ existsSync(new URL("./.prettierrc.yml", import.meta.url)) ||
44
+ existsSync(new URL(".prettierignore", import.meta.url))
45
+ ) {
46
+ prettier = true;
47
+ }
48
+ }
49
+ if (prettierSortImport === undefined) {
50
+ if (devDependencies["prettier-plugin-organize-imports"]) {
51
+ prettierSortImport = true;
52
+ }
53
+ }
54
+
31
55
  const isBrowser = type === "browser";
32
56
  const browserExtensions = [".js", ".jsx"];
33
57
  browserFiles = [