@d-zero/lint-staged-config 5.0.0-dev.93 → 5.0.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/LICENSE +1 -1
- package/README.md +36 -2
- package/dist/commands.d.ts +2 -0
- package/dist/commands.js +9 -0
- package/dist/default-mapping.d.ts +2 -0
- package/dist/default-mapping.js +22 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +62 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/package.json +14 -10
- package/index.mjs +0 -96
- package/types.ts +0 -38
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
# `@d-zero/lint-staged-config`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
## 個別インストール
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install -D @d-zero/lint-staged-config
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 使い方
|
|
10
|
+
|
|
11
|
+
`lint-staged.config.mjs`を作成し、読み込んだジェネレーター関数で設定を生成しエクスポートします。
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import lintStagedConfigGenerator from '@d-zero/lint-staged-config';
|
|
15
|
+
export default lintStagedConfigGenerator();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 拡張
|
|
19
|
+
|
|
20
|
+
プロジェクトに合わせて設定を追加します。
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import lintStagedConfigGenerator, { defaultMapping } from '@d-zero/lint-staged-config';
|
|
24
|
+
export default lintStagedConfigGenerator(
|
|
25
|
+
{
|
|
26
|
+
ignore: [path.resolve(process.cwd(), 'dist', '**', '*')],
|
|
27
|
+
{
|
|
28
|
+
// 例: `CHANGELOG.md`に対してのみ`textlint`を除外する
|
|
29
|
+
textlint: "CHANGELOG.md",
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
...defaultMapping,
|
|
34
|
+
// 例: PHPファイルに対して`markuplint`、`prettier`、`cspell`を実行する
|
|
35
|
+
php: ['markuplint', 'prettier', 'cspell'],
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
```
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const defaultMapping = {
|
|
2
|
+
astro: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
3
|
+
cjs: ['eslint', 'prettier', 'cspell'],
|
|
4
|
+
css: ['stylelint', 'prettier', 'cspell'],
|
|
5
|
+
cts: ['eslint', 'prettier', 'cspell'],
|
|
6
|
+
html: ['markuplint', 'prettier', 'cspell'],
|
|
7
|
+
js: ['eslint', 'prettier', 'cspell'],
|
|
8
|
+
json: ['prettier', 'cspell'],
|
|
9
|
+
jsx: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
10
|
+
md: ['prettier', 'textlint', 'cspell'],
|
|
11
|
+
mdx: ['prettier', 'textlint', 'cspell'],
|
|
12
|
+
mjs: ['eslint', 'prettier', 'cspell'],
|
|
13
|
+
mts: ['eslint', 'prettier', 'cspell'],
|
|
14
|
+
pug: ['markuplint', 'prettier', 'cspell'],
|
|
15
|
+
scss: ['stylelint', 'prettier', 'cspell'],
|
|
16
|
+
svelte: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
17
|
+
ts: ['eslint', 'prettier', 'cspell'],
|
|
18
|
+
tsx: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
19
|
+
vue: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
20
|
+
yaml: ['cspell'],
|
|
21
|
+
yml: ['cspell'],
|
|
22
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommandMappings, CommandType, LintStagedCommandMapper } from './types.js';
|
|
2
|
+
export interface DirectoryOptions {
|
|
3
|
+
/**
|
|
4
|
+
* ファイルを検索するディレクトリ
|
|
5
|
+
*/
|
|
6
|
+
dir?: string;
|
|
7
|
+
/**
|
|
8
|
+
* 除外するファイルのパターン
|
|
9
|
+
*/
|
|
10
|
+
ignore?: (string | IgnoreMap)[];
|
|
11
|
+
}
|
|
12
|
+
export type IgnoreMap = Partial<Record<CommandType, string | string[]>>;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param dirOptions
|
|
16
|
+
* @param mapping
|
|
17
|
+
*/
|
|
18
|
+
export default function (dirOptions?: string | DirectoryOptions, mapping?: CommandMappings): LintStagedCommandMapper;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { commands } from './commands.js';
|
|
3
|
+
import { defaultMapping } from './default-mapping.js';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param dirOptions
|
|
7
|
+
* @param mapping
|
|
8
|
+
*/
|
|
9
|
+
export default function (dirOptions, mapping) {
|
|
10
|
+
return (allStagedFiles) => {
|
|
11
|
+
const commandList = [];
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const dir = typeof dirOptions === 'string' ? dirOptions : dirOptions?.dir;
|
|
14
|
+
const ignore = typeof dirOptions === 'string' ? null : dirOptions?.ignore;
|
|
15
|
+
const baseDir = dir
|
|
16
|
+
? // 絶対パスかどうか
|
|
17
|
+
path.isAbsolute(dir)
|
|
18
|
+
? // 絶対パスならそのまま
|
|
19
|
+
dir
|
|
20
|
+
: // 相対パスなら絶対パスに変換
|
|
21
|
+
path.resolve(cwd, dir)
|
|
22
|
+
: // 引数がないならカレントディレクトリ
|
|
23
|
+
cwd;
|
|
24
|
+
mapping = mapping ?? defaultMapping;
|
|
25
|
+
for (const [ext, commandTypes] of Object.entries(mapping)) {
|
|
26
|
+
for (const commandType of commandTypes) {
|
|
27
|
+
const shell = commands[commandType];
|
|
28
|
+
if (!shell) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const pattern = path
|
|
32
|
+
.resolve(baseDir, '**', `{*.${ext},.*.${ext}}`)
|
|
33
|
+
.replaceAll(path.sep, '/');
|
|
34
|
+
const files = allStagedFiles.map((f) => f.replaceAll(path.sep, '/'));
|
|
35
|
+
let targetFiles = files.filter((file) => path.matchesGlob(file, pattern));
|
|
36
|
+
if (ignore) {
|
|
37
|
+
for (const ignoreMap of ignore) {
|
|
38
|
+
const ignorePattern = typeof ignoreMap === 'string' ? ignoreMap : ignoreMap[commandType];
|
|
39
|
+
if (!ignorePattern) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const ignorePatterns = Array.isArray(ignorePattern)
|
|
43
|
+
? ignorePattern
|
|
44
|
+
: [ignorePattern];
|
|
45
|
+
const absIgnorePatterns = ignorePatterns.map((p) => {
|
|
46
|
+
if (p === path.basename(p)) {
|
|
47
|
+
return path.resolve('**', p).replaceAll(path.sep, '/');
|
|
48
|
+
}
|
|
49
|
+
return path.isAbsolute(p) ? p : path.resolve(baseDir, p);
|
|
50
|
+
});
|
|
51
|
+
targetFiles = targetFiles.filter((file) => !absIgnorePatterns.some((pattern) => path.matchesGlob(file, pattern)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (targetFiles.length <= 0) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
commandList.push(shell + ' ' + targetFiles.map((f) => `"${f}"`).join(' '));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return commandList;
|
|
61
|
+
};
|
|
62
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type TargetFileExtension = 'astro' | 'cjs' | 'css' | 'cts' | 'html' | 'js' | 'json' | 'jsx' | 'md' | 'mdx' | 'mjs' | 'mts' | 'pug' | 'scss' | 'svelte' | 'ts' | 'tsx' | 'vue' | 'yaml' | 'yml';
|
|
2
|
+
export type CommandType = 'cspell' | 'eslint' | 'markuplint' | 'prettier' | 'puglint' | 'stylelint' | 'textlint';
|
|
3
|
+
export type CommandMappings = Readonly<Partial<Record<TargetFileExtension, CommandType[]>>>;
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/okonet/lint-staged#example-export-a-function-to-build-your-own-matchers
|
|
6
|
+
*/
|
|
7
|
+
export type LintStagedCommandMapper = (allStagedFiles: readonly string[]) => string[];
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/lint-staged-config",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Configurations of lint-staged",
|
|
5
|
-
"repository": "https://github.com/d-zero-dev/
|
|
5
|
+
"repository": "https://github.com/d-zero-dev/linters.git",
|
|
6
6
|
"author": "D-ZERO Co., Ltd.",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"private": false,
|
|
9
8
|
"publishConfig": {
|
|
10
9
|
"access": "public"
|
|
11
10
|
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.0.0"
|
|
13
|
+
},
|
|
12
14
|
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
},
|
|
13
19
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"types.ts"
|
|
20
|
+
"dist"
|
|
16
21
|
],
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"types": "./types.ts"
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"lint-staged": "
|
|
26
|
+
"lint-staged": "16.2.7"
|
|
23
27
|
},
|
|
24
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "7f635ad8bbb1455d0d362fe00478a2f7bd216924"
|
|
25
29
|
}
|
package/index.mjs
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import micromatch from 'micromatch';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* lint-staged Config generator
|
|
7
|
-
*
|
|
8
|
-
* @param {string} [dir]
|
|
9
|
-
* @param {import("./types").CommandMappings} [mapping]
|
|
10
|
-
* @return {import("./types").LintStagedCommandMapper}
|
|
11
|
-
*/
|
|
12
|
-
export default function (dir, mapping) {
|
|
13
|
-
return (allStagedFiles) => {
|
|
14
|
-
/**
|
|
15
|
-
* @type {string[]}
|
|
16
|
-
*/
|
|
17
|
-
const commandList = [];
|
|
18
|
-
const cwd = process.cwd();
|
|
19
|
-
|
|
20
|
-
dir = dir
|
|
21
|
-
? // 絶対パスかどうか
|
|
22
|
-
path.isAbsolute(dir)
|
|
23
|
-
? // 絶対パスならそのまま
|
|
24
|
-
dir
|
|
25
|
-
: // 相対パスなら絶対パスに変換
|
|
26
|
-
path.resolve(cwd, dir)
|
|
27
|
-
: // 引数がないならカレントディレクトリ
|
|
28
|
-
cwd;
|
|
29
|
-
|
|
30
|
-
mapping = mapping ?? defaultMapping;
|
|
31
|
-
|
|
32
|
-
for (const [ext, commandTypes] of Object.entries(mapping)) {
|
|
33
|
-
for (const commandType of commandTypes) {
|
|
34
|
-
const shell = commands[commandType];
|
|
35
|
-
|
|
36
|
-
if (!shell) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const pattern = path
|
|
41
|
-
.resolve(dir, '**', `{*.${ext},.*.${ext}}`)
|
|
42
|
-
.replaceAll(path.sep, '/');
|
|
43
|
-
|
|
44
|
-
const files = allStagedFiles.map((f) => f.replaceAll(path.sep, '/'));
|
|
45
|
-
|
|
46
|
-
const targetFiles = micromatch(files, pattern);
|
|
47
|
-
|
|
48
|
-
if (targetFiles.length <= 0) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
commandList.push(shell + ' ' + targetFiles.map((f) => `"${f}"`).join(' '));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return commandList;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @type {Record<import("./types").CommandType, string>}
|
|
62
|
-
*/
|
|
63
|
-
export const commands = {
|
|
64
|
-
cspell: 'cspell --no-must-find-files --show-suggestions',
|
|
65
|
-
eslint: 'eslint --fix',
|
|
66
|
-
markuplint: 'markuplint',
|
|
67
|
-
prettier: 'prettier --write',
|
|
68
|
-
puglint: 'pug-lint',
|
|
69
|
-
stylelint: 'stylelint --fix',
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @type {import("./types").CommandMappings}
|
|
74
|
-
*/
|
|
75
|
-
export const defaultMapping = {
|
|
76
|
-
md: ['prettier', 'textlint', 'cspell'],
|
|
77
|
-
mdx: ['prettier', 'textlint', 'cspell'],
|
|
78
|
-
json: ['prettier', 'cspell'],
|
|
79
|
-
yaml: ['cspell'],
|
|
80
|
-
yml: ['cspell'],
|
|
81
|
-
js: ['eslint', 'prettier', 'cspell'],
|
|
82
|
-
cjs: ['eslint', 'prettier', 'cspell'],
|
|
83
|
-
mjs: ['eslint', 'prettier', 'cspell'],
|
|
84
|
-
jsx: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
85
|
-
ts: ['eslint', 'prettier', 'cspell'],
|
|
86
|
-
cts: ['eslint', 'prettier', 'cspell'],
|
|
87
|
-
mts: ['eslint', 'prettier', 'cspell'],
|
|
88
|
-
tsx: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
89
|
-
html: ['markuplint', 'prettier', 'cspell'],
|
|
90
|
-
pug: ['markuplint', 'prettier', 'cspell'],
|
|
91
|
-
css: ['stylelint', 'prettier', 'cspell'],
|
|
92
|
-
scss: ['stylelint', 'prettier', 'cspell'],
|
|
93
|
-
astro: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
94
|
-
svelte: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
95
|
-
vue: ['eslint', 'markuplint', 'prettier', 'cspell'],
|
|
96
|
-
};
|
package/types.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type TargetFileExtension =
|
|
2
|
-
| 'md'
|
|
3
|
-
| 'mdx'
|
|
4
|
-
| 'json'
|
|
5
|
-
| 'yaml'
|
|
6
|
-
| 'yml'
|
|
7
|
-
| 'js'
|
|
8
|
-
| 'cjs'
|
|
9
|
-
| 'mjs'
|
|
10
|
-
| 'jsx'
|
|
11
|
-
| 'ts'
|
|
12
|
-
| 'cts'
|
|
13
|
-
| 'mts'
|
|
14
|
-
| 'tsx'
|
|
15
|
-
| 'html'
|
|
16
|
-
| 'pug'
|
|
17
|
-
| 'css'
|
|
18
|
-
| 'scss'
|
|
19
|
-
| 'astro'
|
|
20
|
-
| 'svelte'
|
|
21
|
-
| 'vue';
|
|
22
|
-
|
|
23
|
-
export type CommandType =
|
|
24
|
-
| 'cspell'
|
|
25
|
-
| 'eslint'
|
|
26
|
-
| 'markuplint'
|
|
27
|
-
| 'prettier'
|
|
28
|
-
| 'stylelint'
|
|
29
|
-
| 'textlint';
|
|
30
|
-
|
|
31
|
-
export type CommandMappings = Readonly<
|
|
32
|
-
Partial<Record<TargetFileExtension, CommandType[]>>
|
|
33
|
-
>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @see https://github.com/okonet/lint-staged#example-export-a-function-to-build-your-own-matchers
|
|
37
|
-
*/
|
|
38
|
-
export type LintStagedCommandMapper = (allStagedFiles: readonly string[]) => string[];
|