Skip to content

Commit fee99ea

Browse files
authored
Merge pull request #1717 from progfay/eslint-flat-config
Eslint flat config
2 parents dbe081f + 8979b85 commit fee99ea

23 files changed

+130
-73
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
lib
22
esm
33
umd
4-
.eslintrc.js
4+
eslint.config.js

.eslintrc.js

-20
This file was deleted.

eslint.config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import globals from "globals";
2+
import eslint from "@eslint/js";
3+
import tsEslint from "typescript-eslint";
4+
import eslintConfigPrettier from "eslint-config-prettier";
5+
import eslintPluginJest from "eslint-plugin-jest";
6+
7+
/** @type {import("eslint").Linter.FlatConfig[]} */
8+
export default tsEslint.config(
9+
{
10+
ignores: ["lib/**", "esm/**", "umd/**"],
11+
extends: [
12+
eslint.configs.recommended,
13+
...tsEslint.configs.recommended,
14+
eslintConfigPrettier,
15+
],
16+
languageOptions: {
17+
globals: {
18+
...globals.jest,
19+
},
20+
parser: tsEslint.parser,
21+
parserOptions: {
22+
sourceType: "module",
23+
project: "./tsconfig.eslint.json",
24+
},
25+
},
26+
plugins: {
27+
"@typescript-eslint": tsEslint.plugin,
28+
},
29+
},
30+
{
31+
files: ["**/tests/**/*.test.ts"],
32+
...eslintPluginJest.configs["flat/recommended"],
33+
},
34+
);

jest.config.js jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
moduleFileExtensions: ["ts", "js"],
33
transform: {
44
"^.+\\.(ts|tsx)$": "ts-jest",

package-lock.json

+45-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@progfay/scrapbox-parser",
33
"version": "9.0.0",
4+
"type": "module",
45
"description": "parse Scrapbox notation to JavaScript Object",
56
"files": [
67
"lib",
@@ -28,12 +29,12 @@
2829
"test:update": "jest --updateSnapshot --no-cache",
2930
"lint": "run-p lint:*",
3031
"lint:prettier": "prettier --check .",
31-
"lint:eslint": "eslint -c ./.eslintrc.js .",
32+
"lint:eslint": "eslint .",
3233
"lint:cspell": "cspell --no-summary '**/*'",
3334
"lint:typescript": "tsc -p ./tsconfig.eslint.json",
3435
"format": "run-s format:prettier format:eslint",
3536
"format:prettier": "prettier --write .",
36-
"format:eslint": "eslint --fix -c ./.eslintrc.js ."
37+
"format:eslint": "eslint --fix ."
3738
},
3839
"repository": {
3940
"type": "git",
@@ -53,10 +54,9 @@
5354
"@babel/core": "7.24.7",
5455
"@babel/preset-env": "7.24.7",
5556
"@types/core-js": "2.5.8",
57+
"@types/eslint": "8.56.10",
5658
"@types/jest": "29.5.12",
5759
"@types/node": "20.14.10",
58-
"@typescript-eslint/eslint-plugin": "7.16.0",
59-
"@typescript-eslint/parser": "7.16.0",
6060
"babel-loader": "9.1.3",
6161
"cspell": "8.10.4",
6262
"eslint": "8.57.0",
@@ -69,6 +69,7 @@
6969
"ts-jest": "29.2.2",
7070
"ts-loader": "9.5.1",
7171
"typescript": "5.5.3",
72+
"typescript-eslint": "7.16.0",
7273
"webpack": "5.92.1",
7374
"webpack-cli": "5.1.4"
7475
},

src/block/Pack.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const packing = (packs: Pack[], row: Row): Pack[] => {
2222
type: /^\s*code:/.test(row.text)
2323
? "codeBlock"
2424
: /^\s*table:/.test(row.text)
25-
? "table"
26-
: "line",
25+
? "table"
26+
: "line",
2727
rows: [row],
2828
});
2929

src/block/Table.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const convertToTable = (pack: TablePack): Table => {
3737
nested: false,
3838
quoted: false,
3939
context: "table",
40-
})
41-
)
40+
}),
41+
),
4242
),
4343
};
4444
};

src/block/node/CommandLineNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const commandLineRegExp = /^[$%] .+$/;
99

1010
const createCommandLineNode: NodeCreator<CommandLineNode | PlainNode> = (
1111
raw: string,
12-
opts
12+
opts,
1313
) => {
1414
if (opts.context === "table") {
1515
return createPlainNode(raw, opts);
@@ -34,5 +34,5 @@ export const CommandLineNodeParser: NodeParser = createNodeParser(
3434
parseOnNested: false,
3535
parseOnQuoted: false,
3636
patterns: [commandLineRegExp],
37-
}
37+
},
3838
);

src/block/node/DecorationNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type Decoration = Exclude<DecorationChar, "*"> | AsteriskDecorationChar;
5050

5151
const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (
5252
raw,
53-
opts
53+
opts,
5454
) => {
5555
if (opts.context === "table") {
5656
return createPlainNode(raw, opts);
@@ -84,5 +84,5 @@ export const DecorationNodeParser: NodeParser = createNodeParser(
8484
parseOnNested: false,
8585
parseOnQuoted: true,
8686
patterns: [decorationRegExp],
87-
}
87+
},
8888
);

src/block/node/ExternalLinkNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const httpRegExp = /https?:\/\/[^\s]+/;
1212

1313
const createExternalLinkNode: NodeCreator<LinkNode | PlainNode> = (
1414
raw,
15-
opts
15+
opts,
1616
) => {
1717
if (opts.context === "table") {
1818
return createPlainNode(raw, opts);
@@ -55,5 +55,5 @@ export const ExternalLinkNodeParser: NodeParser = createNodeParser(
5555
bracketedUrlRegExp,
5656
httpRegExp,
5757
],
58-
}
58+
},
5959
);

src/block/node/GoogleMapNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const parseCoordinate: (format: string) => Coordinate = (format) => {
2525

2626
const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
2727
raw,
28-
opts
28+
opts,
2929
) => {
3030
if (opts.context === "table") {
3131
return createPlainNode(raw, opts);
@@ -45,7 +45,7 @@ const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
4545
const url =
4646
place !== ""
4747
? `https://www.google.com/maps/place/${encodeURIComponent(
48-
place
48+
place,
4949
)}/@${latitude},${longitude},${zoom}z`
5050
: `https://www.google.com/maps/@${latitude},${longitude},${zoom}z`;
5151

src/block/node/HelpfeelNode.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type { NodeCreator } from "./creator";
66

77
const helpfeelRegExp = /^\? .+$/;
88

9-
const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (raw, opts) =>
9+
const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (
10+
raw,
11+
opts,
12+
) =>
1013
opts.context === "table"
1114
? createPlainNode(raw, opts)
1215
: [

src/block/node/IconNode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import type { NodeCreator } from "./creator";
77
const iconRegExp = /\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;
88

99
export function generateIconNodeCreator(
10-
type: IconNode["type"]
10+
type: IconNode["type"],
1111
): NodeCreator<IconNode>;
1212
export function generateIconNodeCreator(
13-
type: StrongIconNode["type"]
13+
type: StrongIconNode["type"],
1414
): NodeCreator<StrongIconNode | PlainNode>;
1515
export function generateIconNodeCreator(
16-
type: (IconNode | StrongIconNode)["type"]
16+
type: (IconNode | StrongIconNode)["type"],
1717
): NodeCreator<IconNode | StrongIconNode | PlainNode> {
1818
return (raw, opts) => {
1919
if (type === "strongIcon" && opts.context === "table") {

src/block/node/NumberListNode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const numberListRegExp = /^[0-9]+\. .*$/;
99

1010
const createNumberListNode: NodeCreator<NumberListNode | PlainNode> = (
1111
raw,
12-
opts
12+
opts,
1313
) => {
1414
if (opts.context === "table") {
1515
return createPlainNode(raw, opts);

src/block/node/StrongImageNode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const strongGyazoImageRegExp =
1010

1111
const createStrongImageNode: NodeCreator<StrongImageNode | PlainNode> = (
1212
raw,
13-
opts
13+
opts,
1414
) => {
1515
if (opts.context === "table") {
1616
return createPlainNode(raw, opts);

src/block/node/creator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import type { Node } from "./type";
55

66
export type NodeCreator<T extends Node> = (
77
target: string,
8-
opts: NodeParserOption
8+
opts: NodeParserOption,
99
) => T[];
1010

1111
type NodeParserCreator<T extends Node> = (
1212
nodeCreator: NodeCreator<T>,
13-
opts: { parseOnNested: boolean; parseOnQuoted: boolean; patterns: RegExp[] }
13+
opts: { parseOnNested: boolean; parseOnQuoted: boolean; patterns: RegExp[] },
1414
) => NodeParser;
1515

1616
export const createNodeParser: NodeParserCreator<Node> = (
1717
nodeCreator,
18-
{ parseOnNested, parseOnQuoted, patterns }
18+
{ parseOnNested, parseOnQuoted, patterns },
1919
) => {
2020
return (text, opts, next) => {
2121
if (!parseOnNested && opts.nested) return next?.() ?? [];

src/block/node/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type NextNodeParser = () => Node[];
2828
export type NodeParser = (
2929
text: string,
3030
opts: NodeParserOption,
31-
next?: NextNodeParser
31+
next?: NextNodeParser,
3232
) => Node[];
3333

3434
const FalsyEliminator: NodeParser = (text, _, next) => {
@@ -43,7 +43,7 @@ const combineNodeParsers =
4343
(acc: NextNodeParser, parser: NodeParser): NextNodeParser =>
4444
() =>
4545
parser(text, opts, acc),
46-
() => PlainNodeParser(text, opts)
46+
() => PlainNodeParser(text, opts),
4747
)();
4848

4949
export const convertToNodes: ReturnType<typeof combineNodeParsers> =
@@ -65,5 +65,5 @@ export const convertToNodes: ReturnType<typeof combineNodeParsers> =
6565
GoogleMapNodeParser,
6666
InternalLinkNodeParser,
6767
HashTagNodeParser,
68-
NumberListNodeParser
68+
NumberListNodeParser,
6969
);

tests/jest-setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ expect.extend({
2323
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2424
this: any,
2525
received: string,
26-
opts?: ParserOption
26+
opts?: ParserOption,
2727
) {
2828
const blocks = parse(received, opts);
2929
return toMatchSnapshot.call(this, blocks);

0 commit comments

Comments
 (0)