@fullstacksjs/eslint-config 12.4.0 → 12.4.1

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/cjs/index.d.ts CHANGED
@@ -97,10 +97,10 @@ export interface Options extends Linter.Config {
97
97
  */
98
98
  ignores?: string[];
99
99
  /**
100
- * .gitignore file path relative to ESLint configuration file.
100
+ * .gitignore file path relative to ESLint configuration file. Set to `false` to disable.
101
101
  * @default './.gitignore'
102
102
  */
103
- gitignorePath?: string;
103
+ gitignore?: string | false;
104
104
  }
105
105
 
106
106
  export declare function defineConfig(initOptions?: Options, ...extend: Linter.Config[]): Linter.Config[];
package/cjs/index.js CHANGED
@@ -39,7 +39,7 @@ const defaultOptions = {
39
39
  disableExpensiveRules: false,
40
40
  esm: false,
41
41
  ignores: [],
42
- gitignorePath: './.gitignore',
42
+ gitignore: './.gitignore',
43
43
  import: {},
44
44
  jest: (0, _localPkg.isPackageExists)('jest'),
45
45
  next: (0, _localPkg.isPackageExists)('next'),
@@ -79,7 +79,7 @@ function defineConfig(initOptions = {}, ...extend) {
79
79
  disableExpensiveRules,
80
80
  esm: enableEsm,
81
81
  ignores: enableIgnores,
82
- gitignorePath,
82
+ gitignore,
83
83
  import: enableImport,
84
84
  jest: enableJest,
85
85
  next: enableNext,
@@ -4,18 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _compat = require("@eslint/compat");
8
7
  var _config = require("eslint/config");
9
- var _nodePath = _interopRequireDefault(require("node:path"));
8
+ var _getGitignorePatterns = require("../utils/getGitignorePatterns.js");
10
9
  var _globs = require("../utils/globs.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
10
  /**
13
11
  * @param { import('../index.js').Options } options
14
12
  * @return { import('eslint').Linter.Config }
15
13
  */
16
14
  function ignores(options = {}) {
17
- const gitignorePath = _nodePath.default.resolve(process.cwd(), options.gitignorePath);
18
- const gitignore = (0, _compat.includeIgnoreFile)(gitignorePath);
19
- return (0, _config.globalIgnores)([...gitignore.ignores, ..._globs.ignoreGlobs, ...(options.ignores ?? [])], 'ignores');
15
+ const ignorePatterns = [..._globs.ignoreGlobs, ...(options.ignores ?? [])];
16
+ const shouldUseGitignore = options.gitignore && options.gitignore.length > 0;
17
+ if (shouldUseGitignore) {
18
+ const gitignorePatterns = (0, _getGitignorePatterns.getGitignorePatterns)(options.gitignore);
19
+ if (gitignorePatterns.length > 0) {
20
+ ignorePatterns.push(...gitignorePatterns);
21
+ }
22
+ }
23
+ const uniqueIgnorePatterns = [...new Set(ignorePatterns)];
24
+ return (0, _config.globalIgnores)(uniqueIgnorePatterns, 'ignores');
20
25
  }
21
26
  module.exports = ignores;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getGitignorePatterns = getGitignorePatterns;
7
+ var _compat = require("@eslint/compat");
8
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
9
+ var _nodePath = _interopRequireDefault(require("node:path"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /* eslint 'no-console': ['warn', { allow: ['warn'] }] */
12
+
13
+ const warningMessage = '\u001B[38;2;229;229;14mWarning:\u001B[0m';
14
+ const fallbackMessage = 'Falling back to default ignore patterns. You can suppress this warning by setting \u001B[48;5;234m`gitignore: false`\u001B[0m in the config.';
15
+
16
+ /**
17
+ * @param {string} gitignorePath relative path to the .gitignore file
18
+ * @returns {string[]}
19
+ */
20
+ function getGitignorePatterns(gitignorePath) {
21
+ const gitignoreAbsolutePath = _nodePath.default.resolve(process.cwd(), gitignorePath);
22
+ const gitignoreExists = _nodeFs.default.existsSync(gitignoreAbsolutePath); // eslint-disable-line n/no-sync
23
+ const gitignorePatterns = [];
24
+ if (!gitignoreExists) {
25
+ console.warn(warningMessage, `No .gitignore file found at "${gitignoreAbsolutePath}".`, fallbackMessage);
26
+ return gitignorePatterns;
27
+ }
28
+ const ignorePatterns = (0, _compat.includeIgnoreFile)(gitignoreAbsolutePath).ignores ?? [];
29
+ if (ignorePatterns.length > 0) {
30
+ gitignorePatterns.push(...ignorePatterns);
31
+ } else {
32
+ console.warn(warningMessage, `No patterns found in .gitignore file at "${gitignoreAbsolutePath}".`, fallbackMessage);
33
+ }
34
+ return gitignorePatterns;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstacksjs/eslint-config",
3
- "version": "12.4.0",
3
+ "version": "12.4.1",
4
4
  "license": "MIT",
5
5
  "author": "fullstacks <fullstacksjs@gmail.com>",
6
6
  "description": "fullstacks eslint config",
@@ -23,7 +23,7 @@
23
23
  "postbuild": "./postbuild",
24
24
  "prepublishOnly": "pinst --disable",
25
25
  "postpublish": "pinst --enable",
26
- "pre-commit": "npm run test && lint-staged"
26
+ "pre-commit": "npm run test && lint-staged && npm run spell"
27
27
  },
28
28
  "main": "./cjs/index.js",
29
29
  "module": "./src/index.mjs",
package/src/index.d.ts CHANGED
@@ -97,10 +97,10 @@ export interface Options extends Linter.Config {
97
97
  */
98
98
  ignores?: string[];
99
99
  /**
100
- * .gitignore file path relative to ESLint configuration file.
100
+ * .gitignore file path relative to ESLint configuration file. Set to `false` to disable.
101
101
  * @default './.gitignore'
102
102
  */
103
- gitignorePath?: string;
103
+ gitignore?: string | false;
104
104
  }
105
105
 
106
106
  export declare function defineConfig(initOptions?: Options, ...extend: Linter.Config[]): Linter.Config[];
package/src/index.mjs CHANGED
@@ -33,7 +33,7 @@ const defaultOptions = {
33
33
  disableExpensiveRules: false,
34
34
  esm: false,
35
35
  ignores: [],
36
- gitignorePath: './.gitignore',
36
+ gitignore: './.gitignore',
37
37
  import: {},
38
38
  jest: isPackageExists('jest'),
39
39
  next: isPackageExists('next'),
@@ -72,7 +72,7 @@ export function defineConfig(initOptions = {}, ...extend) {
72
72
  disableExpensiveRules,
73
73
  esm: enableEsm,
74
74
  ignores: enableIgnores,
75
- gitignorePath,
75
+ gitignore,
76
76
  import: enableImport,
77
77
  jest: enableJest,
78
78
  next: enableNext,
@@ -1,7 +1,6 @@
1
- import { includeIgnoreFile } from '@eslint/compat';
2
1
  import { globalIgnores } from 'eslint/config';
3
- import path from 'node:path';
4
2
 
3
+ import { getGitignorePatterns } from '../utils/getGitignorePatterns.mjs';
5
4
  import { ignoreGlobs } from '../utils/globs.mjs';
6
5
 
7
6
  /**
@@ -9,9 +8,19 @@ import { ignoreGlobs } from '../utils/globs.mjs';
9
8
  * @return { import('eslint').Linter.Config }
10
9
  */
11
10
  function ignores(options = {}) {
12
- const gitignorePath = path.resolve(process.cwd(), options.gitignorePath);
13
- const gitignore = includeIgnoreFile(gitignorePath);
14
- return globalIgnores([...gitignore.ignores, ...ignoreGlobs, ...(options.ignores ?? [])], 'ignores');
11
+ const ignorePatterns = [...ignoreGlobs, ...(options.ignores ?? [])];
12
+
13
+ const shouldUseGitignore = options.gitignore && options.gitignore.length > 0;
14
+ if (shouldUseGitignore) {
15
+ const gitignorePatterns = getGitignorePatterns(options.gitignore);
16
+ if (gitignorePatterns.length > 0) {
17
+ ignorePatterns.push(...gitignorePatterns);
18
+ }
19
+ }
20
+
21
+ const uniqueIgnorePatterns = [...new Set(ignorePatterns)];
22
+
23
+ return globalIgnores(uniqueIgnorePatterns, 'ignores');
15
24
  }
16
25
 
17
26
  export default ignores;
@@ -0,0 +1,35 @@
1
+ /* eslint 'no-console': ['warn', { allow: ['warn'] }] */
2
+
3
+ import { includeIgnoreFile } from '@eslint/compat';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+
7
+ const warningMessage = '\u001B[38;2;229;229;14mWarning:\u001B[0m';
8
+ const fallbackMessage =
9
+ 'Falling back to default ignore patterns. You can suppress this warning by setting \u001B[48;5;234m`gitignore: false`\u001B[0m in the config.';
10
+
11
+ /**
12
+ * @param {string} gitignorePath relative path to the .gitignore file
13
+ * @returns {string[]}
14
+ */
15
+ export function getGitignorePatterns(gitignorePath) {
16
+ const gitignoreAbsolutePath = path.resolve(process.cwd(), gitignorePath);
17
+ const gitignoreExists = fs.existsSync(gitignoreAbsolutePath); // eslint-disable-line n/no-sync
18
+ const gitignorePatterns = [];
19
+
20
+ if (!gitignoreExists) {
21
+ console.warn(warningMessage, `No .gitignore file found at "${gitignoreAbsolutePath}".`, fallbackMessage);
22
+
23
+ return gitignorePatterns;
24
+ }
25
+
26
+ const ignorePatterns = includeIgnoreFile(gitignoreAbsolutePath).ignores ?? [];
27
+
28
+ if (ignorePatterns.length > 0) {
29
+ gitignorePatterns.push(...ignorePatterns);
30
+ } else {
31
+ console.warn(warningMessage, `No patterns found in .gitignore file at "${gitignoreAbsolutePath}".`, fallbackMessage);
32
+ }
33
+
34
+ return gitignorePatterns;
35
+ }