@szum-tech/eslint-config 2.1.2 → 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,14 +15,31 @@ 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
- var importPlugin__default = /*#__PURE__*/_interopDefault(importPlugin);
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var importPlugin__namespace = /*#__PURE__*/_interopNamespace(importPlugin);
20
39
  var jestDomPlugin__default = /*#__PURE__*/_interopDefault(jestDomPlugin);
21
40
  var playwrightPlugin__default = /*#__PURE__*/_interopDefault(playwrightPlugin);
22
41
  var reactPlugin__default = /*#__PURE__*/_interopDefault(reactPlugin);
23
- var reactHooksPlugin__default = /*#__PURE__*/_interopDefault(reactHooksPlugin);
42
+ var reactHooksPlugin__namespace = /*#__PURE__*/_interopNamespace(reactHooksPlugin);
24
43
  var storybookPlugin__default = /*#__PURE__*/_interopDefault(storybookPlugin);
25
44
  var tailwindcssPlugin__default = /*#__PURE__*/_interopDefault(tailwindcssPlugin);
26
45
  var testingLibraryPlugin__default = /*#__PURE__*/_interopDefault(testingLibraryPlugin);
@@ -33,28 +52,75 @@ var vitestPlugin__default = /*#__PURE__*/_interopDefault(vitestPlugin);
33
52
  var ERROR = "error";
34
53
  var WARN = "warn";
35
54
  var OFF = "off";
36
- 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);
37
73
  try {
38
- 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)));
39
- return true;
40
- } catch {
41
- 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);
42
82
  }
43
- };
44
- var hasTypeScript = has("typescript");
45
- var hasTailwindcss = has("tailwindcss");
46
- var hasReact = has("react");
47
- var hasNext = has("next");
48
- var hasTestingLibrary = has("@testing-library/dom");
49
- var hasJestDom = has("@testing-library/jest-dom");
50
- var hasVitest = has("vitest");
51
- var hasPlaywright = has("@playwright/test");
52
- 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");
53
93
  var typeScriptExtensions = [".ts", ".cts", ".mts", ".tsx"];
54
94
  var allExtensions = [...typeScriptExtensions, ".js", ".jsx", ".mjs", ".cjs"];
55
95
  var vitestFiles = ["**/__tests__/**/*", "**/*.test.*"];
56
96
  var testFiles = ["**/tests/**", ...vitestFiles];
57
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();
58
124
  var config = [
59
125
  {
60
126
  name: "eslint/ignores",
@@ -72,7 +138,7 @@ var config = [
72
138
  {
73
139
  name: "eslint/config/base&import",
74
140
  plugins: {
75
- import: importPlugin__default.default.flatConfigs.recommended.plugins.import
141
+ import: importPlugin__namespace
76
142
  },
77
143
  languageOptions: {
78
144
  ecmaVersion: "latest",
@@ -85,6 +151,18 @@ var config = [
85
151
  warnOnUnsupportedTypeScriptVersion: false
86
152
  }
87
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
+ } : {},
88
166
  rules: {
89
167
  "no-unexpected-multiline": ERROR,
90
168
  "no-warning-comments": [ERROR, { terms: ["FIXME"], location: "anywhere" }],
@@ -136,7 +214,7 @@ var config = [
136
214
  files: ["**/*.tsx", "**/*.jsx"],
137
215
  plugins: {
138
216
  react: reactPlugin__default.default,
139
- "react-hooks": reactHooksPlugin__default.default
217
+ "react-hooks": reactHooksPlugin__namespace
140
218
  },
141
219
  languageOptions: {
142
220
  parser: tsEslint__default.default.parser,
@@ -240,18 +318,6 @@ var config = [
240
318
  plugins: {
241
319
  "@typescript-eslint": tsEslint__default.default.plugin
242
320
  },
243
- settings: {
244
- "import/extensions": allExtensions,
245
- "import/external-module-folders": ["node_modules", "node_modules/@types"],
246
- "import/parsers": {
247
- "@typescript-eslint/parser": typeScriptExtensions
248
- },
249
- "import/resolver": {
250
- node: {
251
- extensions: allExtensions
252
- }
253
- }
254
- },
255
321
  rules: {
256
322
  "no-unused-expressions": OFF,
257
323
  "no-array-constructor": OFF,
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- import importPlugin from 'eslint-plugin-import';
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
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",
@@ -54,7 +103,7 @@ var config = [
54
103
  {
55
104
  name: "eslint/config/base&import",
56
105
  plugins: {
57
- import: importPlugin.flatConfigs.recommended.plugins.import
106
+ import: importPlugin
58
107
  },
59
108
  languageOptions: {
60
109
  ecmaVersion: "latest",
@@ -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.2",
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
  ],