@szum-tech/eslint-config 2.1.3 → 2.1.4

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/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var fs = require('fs');
4
+ var path = require('path');
3
5
  var importPlugin = require('eslint-plugin-import');
4
6
  var jestDomPlugin = require('eslint-plugin-jest-dom');
5
7
  var playwrightPlugin = require('eslint-plugin-playwright');
@@ -13,7 +15,6 @@ var tsEslint = require('typescript-eslint');
13
15
  var nextPlugin = require('@next/eslint-plugin-next');
14
16
  var vitestPlugin = require('@vitest/eslint-plugin');
15
17
 
16
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
19
 
19
20
  function _interopNamespace(e) {
@@ -38,7 +39,7 @@ var importPlugin__namespace = /*#__PURE__*/_interopNamespace(importPlugin);
38
39
  var jestDomPlugin__default = /*#__PURE__*/_interopDefault(jestDomPlugin);
39
40
  var playwrightPlugin__default = /*#__PURE__*/_interopDefault(playwrightPlugin);
40
41
  var reactPlugin__default = /*#__PURE__*/_interopDefault(reactPlugin);
41
- var reactHooksPlugin__default = /*#__PURE__*/_interopDefault(reactHooksPlugin);
42
+ var reactHooksPlugin__namespace = /*#__PURE__*/_interopNamespace(reactHooksPlugin);
42
43
  var storybookPlugin__default = /*#__PURE__*/_interopDefault(storybookPlugin);
43
44
  var tailwindcssPlugin__default = /*#__PURE__*/_interopDefault(tailwindcssPlugin);
44
45
  var testingLibraryPlugin__default = /*#__PURE__*/_interopDefault(testingLibraryPlugin);
@@ -51,28 +52,75 @@ var vitestPlugin__default = /*#__PURE__*/_interopDefault(vitestPlugin);
51
52
  var ERROR = "error";
52
53
  var WARN = "warn";
53
54
  var OFF = "off";
54
- var has = (pkg) => {
55
+ function findPackageJson(startDir) {
56
+ let currentDir = startDir;
57
+ while (true) {
58
+ const packageJsonPath = path.join(currentDir, "package.json");
59
+ if (fs.existsSync(packageJsonPath)) {
60
+ return packageJsonPath;
61
+ }
62
+ const parentDir = path.resolve(currentDir, "..");
63
+ if (parentDir === currentDir) {
64
+ break;
65
+ }
66
+ currentDir = parentDir;
67
+ }
68
+ return null;
69
+ }
70
+ function isPackageInstalled(packageName) {
71
+ const currentDir = process.cwd();
72
+ const packageJsonPath = findPackageJson(currentDir);
55
73
  try {
56
- undefined(pkg, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
57
- return true;
58
- } catch {
59
- return false;
74
+ const packageJson = fs.readFileSync(packageJsonPath, "utf-8");
75
+ const parsedPackageJson = JSON.parse(packageJson);
76
+ const dependencies = parsedPackageJson.dependencies || {};
77
+ const devDependencies = parsedPackageJson.devDependencies || {};
78
+ return dependencies.hasOwnProperty(packageName) || devDependencies.hasOwnProperty(packageName);
79
+ } catch (error) {
80
+ console.error("Error reading package.json file:", error);
81
+ process.exit(1);
60
82
  }
61
- };
62
- var hasTypeScript = has("typescript");
63
- var hasTailwindcss = has("tailwindcss");
64
- var hasReact = has("react");
65
- var hasNext = has("next");
66
- var hasTestingLibrary = has("@testing-library/dom");
67
- var hasJestDom = has("@testing-library/jest-dom");
68
- var hasVitest = has("vitest");
69
- var hasPlaywright = has("@playwright/test");
70
- var hasStorybook = has("storybook");
83
+ }
84
+ var hasTypeScript = isPackageInstalled("typescript");
85
+ var hasTailwindcss = isPackageInstalled("tailwindcss");
86
+ var hasReact = isPackageInstalled("react");
87
+ var hasNext = isPackageInstalled("next");
88
+ var hasTestingLibrary = isPackageInstalled("@testing-library/dom");
89
+ var hasJestDom = isPackageInstalled("@testing-library/jest-dom");
90
+ var hasVitest = isPackageInstalled("vitest");
91
+ var hasPlaywright = isPackageInstalled("@playwright/test");
92
+ var hasStorybook = isPackageInstalled("storybook");
71
93
  var typeScriptExtensions = [".ts", ".cts", ".mts", ".tsx"];
72
94
  var allExtensions = [...typeScriptExtensions, ".js", ".jsx", ".mjs", ".cjs"];
73
95
  var vitestFiles = ["**/__tests__/**/*", "**/*.test.*"];
74
96
  var testFiles = ["**/tests/**", ...vitestFiles];
75
97
  var playwrightFiles = ["**/e2e/**", "**/*.e2e.*"];
98
+ function showFeaturesTable() {
99
+ console.log("Hello There!\nHere are the features detected in your project:");
100
+ const tableData = [
101
+ { Name: "TypeScript", Status: hasTypeScript ? "\u2714\uFE0F" : "\u274C" },
102
+ { Name: "React", Status: hasReact ? "\u2714\uFE0F" : "\u274C" },
103
+ { Name: "Next", Status: hasNext ? "\u2714\uFE0F" : "\u274C" },
104
+ { Name: "Testing Library", Status: hasTestingLibrary ? "\u2714\uFE0F" : "\u274C" },
105
+ { Name: "Jest Dom", Status: hasJestDom ? "\u2714\uFE0F" : "\u274C" },
106
+ { Name: "Vitest", Status: hasVitest ? "\u2714\uFE0F" : "\u274C" },
107
+ { Name: "Playwright", Status: hasPlaywright ? "\u2714\uFE0F" : "\u274C" },
108
+ { Name: "Storybook", Status: hasStorybook ? "\u2714\uFE0F" : "\u274C" }
109
+ ].sort((a, b) => {
110
+ const aHasCheck = a.Status.includes("\u2714\uFE0F");
111
+ const bHasCheck = b.Status.includes("\u2714\uFE0F");
112
+ if (aHasCheck && !bHasCheck) {
113
+ return -1;
114
+ } else if (!aHasCheck && bHasCheck) {
115
+ return 1;
116
+ } else {
117
+ return 0;
118
+ }
119
+ });
120
+ console.table(tableData);
121
+ console.log("Thank you for using @szum-tech/eslint-config!");
122
+ }
123
+ showFeaturesTable();
76
124
  var config = [
77
125
  {
78
126
  name: "eslint/ignores",
@@ -103,6 +151,18 @@ var config = [
103
151
  warnOnUnsupportedTypeScriptVersion: false
104
152
  }
105
153
  },
154
+ settings: hasTypeScript ? {
155
+ "import/extensions": allExtensions,
156
+ "import/external-module-folders": ["node_modules", "node_modules/@types"],
157
+ "import/parsers": {
158
+ "@typescript-eslint/parser": typeScriptExtensions
159
+ },
160
+ "import/resolver": {
161
+ node: {
162
+ extensions: allExtensions
163
+ }
164
+ }
165
+ } : {},
106
166
  rules: {
107
167
  "no-unexpected-multiline": ERROR,
108
168
  "no-warning-comments": [ERROR, { terms: ["FIXME"], location: "anywhere" }],
@@ -154,7 +214,7 @@ var config = [
154
214
  files: ["**/*.tsx", "**/*.jsx"],
155
215
  plugins: {
156
216
  react: reactPlugin__default.default,
157
- "react-hooks": reactHooksPlugin__default.default
217
+ "react-hooks": reactHooksPlugin__namespace
158
218
  },
159
219
  languageOptions: {
160
220
  parser: tsEslint__default.default.parser,
@@ -258,18 +318,6 @@ var config = [
258
318
  plugins: {
259
319
  "@typescript-eslint": tsEslint__default.default.plugin
260
320
  },
261
- settings: {
262
- "import/extensions": allExtensions,
263
- "import/external-module-folders": ["node_modules", "node_modules/@types"],
264
- "import/parsers": {
265
- "@typescript-eslint/parser": typeScriptExtensions
266
- },
267
- "import/resolver": {
268
- node: {
269
- extensions: allExtensions
270
- }
271
- }
272
- },
273
321
  rules: {
274
322
  "no-unused-expressions": OFF,
275
323
  "no-array-constructor": OFF,
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
1
3
  import * as importPlugin from 'eslint-plugin-import';
2
4
  import jestDomPlugin from 'eslint-plugin-jest-dom';
3
5
  import playwrightPlugin from 'eslint-plugin-playwright';
4
6
  import reactPlugin from 'eslint-plugin-react';
5
- import reactHooksPlugin from 'eslint-plugin-react-hooks';
7
+ import * as reactHooksPlugin from 'eslint-plugin-react-hooks';
6
8
  import storybookPlugin from 'eslint-plugin-storybook';
7
9
  import tailwindcssPlugin from 'eslint-plugin-tailwindcss';
8
10
  import testingLibraryPlugin from 'eslint-plugin-testing-library';
@@ -15,28 +17,75 @@ import vitestPlugin from '@vitest/eslint-plugin';
15
17
  var ERROR = "error";
16
18
  var WARN = "warn";
17
19
  var OFF = "off";
18
- var has = (pkg) => {
20
+ function findPackageJson(startDir) {
21
+ let currentDir = startDir;
22
+ while (true) {
23
+ const packageJsonPath = join(currentDir, "package.json");
24
+ if (existsSync(packageJsonPath)) {
25
+ return packageJsonPath;
26
+ }
27
+ const parentDir = resolve(currentDir, "..");
28
+ if (parentDir === currentDir) {
29
+ break;
30
+ }
31
+ currentDir = parentDir;
32
+ }
33
+ return null;
34
+ }
35
+ function isPackageInstalled(packageName) {
36
+ const currentDir = process.cwd();
37
+ const packageJsonPath = findPackageJson(currentDir);
19
38
  try {
20
- import.meta.resolve(pkg, import.meta.url);
21
- return true;
22
- } catch {
23
- return false;
39
+ const packageJson = readFileSync(packageJsonPath, "utf-8");
40
+ const parsedPackageJson = JSON.parse(packageJson);
41
+ const dependencies = parsedPackageJson.dependencies || {};
42
+ const devDependencies = parsedPackageJson.devDependencies || {};
43
+ return dependencies.hasOwnProperty(packageName) || devDependencies.hasOwnProperty(packageName);
44
+ } catch (error) {
45
+ console.error("Error reading package.json file:", error);
46
+ process.exit(1);
24
47
  }
25
- };
26
- var hasTypeScript = has("typescript");
27
- var hasTailwindcss = has("tailwindcss");
28
- var hasReact = has("react");
29
- var hasNext = has("next");
30
- var hasTestingLibrary = has("@testing-library/dom");
31
- var hasJestDom = has("@testing-library/jest-dom");
32
- var hasVitest = has("vitest");
33
- var hasPlaywright = has("@playwright/test");
34
- var hasStorybook = has("storybook");
48
+ }
49
+ var hasTypeScript = isPackageInstalled("typescript");
50
+ var hasTailwindcss = isPackageInstalled("tailwindcss");
51
+ var hasReact = isPackageInstalled("react");
52
+ var hasNext = isPackageInstalled("next");
53
+ var hasTestingLibrary = isPackageInstalled("@testing-library/dom");
54
+ var hasJestDom = isPackageInstalled("@testing-library/jest-dom");
55
+ var hasVitest = isPackageInstalled("vitest");
56
+ var hasPlaywright = isPackageInstalled("@playwright/test");
57
+ var hasStorybook = isPackageInstalled("storybook");
35
58
  var typeScriptExtensions = [".ts", ".cts", ".mts", ".tsx"];
36
59
  var allExtensions = [...typeScriptExtensions, ".js", ".jsx", ".mjs", ".cjs"];
37
60
  var vitestFiles = ["**/__tests__/**/*", "**/*.test.*"];
38
61
  var testFiles = ["**/tests/**", ...vitestFiles];
39
62
  var playwrightFiles = ["**/e2e/**", "**/*.e2e.*"];
63
+ function showFeaturesTable() {
64
+ console.log("Hello There!\nHere are the features detected in your project:");
65
+ const tableData = [
66
+ { Name: "TypeScript", Status: hasTypeScript ? "\u2714\uFE0F" : "\u274C" },
67
+ { Name: "React", Status: hasReact ? "\u2714\uFE0F" : "\u274C" },
68
+ { Name: "Next", Status: hasNext ? "\u2714\uFE0F" : "\u274C" },
69
+ { Name: "Testing Library", Status: hasTestingLibrary ? "\u2714\uFE0F" : "\u274C" },
70
+ { Name: "Jest Dom", Status: hasJestDom ? "\u2714\uFE0F" : "\u274C" },
71
+ { Name: "Vitest", Status: hasVitest ? "\u2714\uFE0F" : "\u274C" },
72
+ { Name: "Playwright", Status: hasPlaywright ? "\u2714\uFE0F" : "\u274C" },
73
+ { Name: "Storybook", Status: hasStorybook ? "\u2714\uFE0F" : "\u274C" }
74
+ ].sort((a, b) => {
75
+ const aHasCheck = a.Status.includes("\u2714\uFE0F");
76
+ const bHasCheck = b.Status.includes("\u2714\uFE0F");
77
+ if (aHasCheck && !bHasCheck) {
78
+ return -1;
79
+ } else if (!aHasCheck && bHasCheck) {
80
+ return 1;
81
+ } else {
82
+ return 0;
83
+ }
84
+ });
85
+ console.table(tableData);
86
+ console.log("Thank you for using @szum-tech/eslint-config!");
87
+ }
88
+ showFeaturesTable();
40
89
  var config = [
41
90
  {
42
91
  name: "eslint/ignores",
@@ -67,6 +116,18 @@ var config = [
67
116
  warnOnUnsupportedTypeScriptVersion: false
68
117
  }
69
118
  },
119
+ settings: hasTypeScript ? {
120
+ "import/extensions": allExtensions,
121
+ "import/external-module-folders": ["node_modules", "node_modules/@types"],
122
+ "import/parsers": {
123
+ "@typescript-eslint/parser": typeScriptExtensions
124
+ },
125
+ "import/resolver": {
126
+ node: {
127
+ extensions: allExtensions
128
+ }
129
+ }
130
+ } : {},
70
131
  rules: {
71
132
  "no-unexpected-multiline": ERROR,
72
133
  "no-warning-comments": [ERROR, { terms: ["FIXME"], location: "anywhere" }],
@@ -222,18 +283,6 @@ var config = [
222
283
  plugins: {
223
284
  "@typescript-eslint": tsEslint.plugin
224
285
  },
225
- settings: {
226
- "import/extensions": allExtensions,
227
- "import/external-module-folders": ["node_modules", "node_modules/@types"],
228
- "import/parsers": {
229
- "@typescript-eslint/parser": typeScriptExtensions
230
- },
231
- "import/resolver": {
232
- node: {
233
- extensions: allExtensions
234
- }
235
- }
236
- },
237
286
  rules: {
238
287
  "no-unused-expressions": OFF,
239
288
  "no-array-constructor": OFF,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@szum-tech/eslint-config",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "ESLint configuration for TypeScript projects",
5
5
  "keywords": [
6
6
  "eslint",
@@ -21,7 +21,7 @@
21
21
  "author": "Jan Szewczyk (Szum-Tech)",
22
22
  "type": "module",
23
23
  "main": "./dist/index.cjs",
24
- "module": ".dist/index.js",
24
+ "module": "./dist/index.js",
25
25
  "files": [
26
26
  "dist/**"
27
27
  ],