Skip to content

Eslint flat config #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib
esm
umd
.eslintrc.js
eslint.config.js
20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

34 changes: 34 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import globals from "globals";
import eslint from "@eslint/js";
import tsEslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";
import eslintPluginJest from "eslint-plugin-jest";

/** @type {import("eslint").Linter.FlatConfig[]} */
export default tsEslint.config(
{
ignores: ["lib/**", "esm/**", "umd/**"],
extends: [
eslint.configs.recommended,
...tsEslint.configs.recommended,
eslintConfigPrettier,
],
languageOptions: {
globals: {
...globals.jest,
},
parser: tsEslint.parser,
parserOptions: {
sourceType: "module",
project: "./tsconfig.eslint.json",
},
},
plugins: {
"@typescript-eslint": tsEslint.plugin,
},
},
{
files: ["**/tests/**/*.test.ts"],
...eslintPluginJest.configs["flat/recommended"],
},
);
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
53 changes: 45 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@progfay/scrapbox-parser",
"version": "9.0.0",
"type": "module",
"description": "parse Scrapbox notation to JavaScript Object",
"files": [
"lib",
@@ -28,12 +29,12 @@
"test:update": "jest --updateSnapshot --no-cache",
"lint": "run-p lint:*",
"lint:prettier": "prettier --check .",
"lint:eslint": "eslint -c ./.eslintrc.js .",
"lint:eslint": "eslint .",
"lint:cspell": "cspell --no-summary '**/*'",
"lint:typescript": "tsc -p ./tsconfig.eslint.json",
"format": "run-s format:prettier format:eslint",
"format:prettier": "prettier --write .",
"format:eslint": "eslint --fix -c ./.eslintrc.js ."
"format:eslint": "eslint --fix ."
},
"repository": {
"type": "git",
@@ -53,10 +54,9 @@
"@babel/core": "7.24.7",
"@babel/preset-env": "7.24.7",
"@types/core-js": "2.5.8",
"@types/eslint": "8.56.10",
"@types/jest": "29.5.12",
"@types/node": "20.14.10",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"babel-loader": "9.1.3",
"cspell": "8.10.4",
"eslint": "8.57.0",
@@ -69,6 +69,7 @@
"ts-jest": "29.2.2",
"ts-loader": "9.5.1",
"typescript": "5.5.3",
"typescript-eslint": "7.16.0",
"webpack": "5.92.1",
"webpack-cli": "5.1.4"
},
4 changes: 2 additions & 2 deletions src/block/Pack.ts
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ const packing = (packs: Pack[], row: Row): Pack[] => {
type: /^\s*code:/.test(row.text)
? "codeBlock"
: /^\s*table:/.test(row.text)
? "table"
: "line",
? "table"
: "line",
rows: [row],
});

4 changes: 2 additions & 2 deletions src/block/Table.ts
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ export const convertToTable = (pack: TablePack): Table => {
nested: false,
quoted: false,
context: "table",
})
)
}),
),
),
};
};
4 changes: 2 additions & 2 deletions src/block/node/CommandLineNode.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const commandLineRegExp = /^[$%] .+$/;

const createCommandLineNode: NodeCreator<CommandLineNode | PlainNode> = (
raw: string,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
@@ -34,5 +34,5 @@ export const CommandLineNodeParser: NodeParser = createNodeParser(
parseOnNested: false,
parseOnQuoted: false,
patterns: [commandLineRegExp],
}
},
);
4 changes: 2 additions & 2 deletions src/block/node/DecorationNode.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ export type Decoration = Exclude<DecorationChar, "*"> | AsteriskDecorationChar;

const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (
raw,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
@@ -84,5 +84,5 @@ export const DecorationNodeParser: NodeParser = createNodeParser(
parseOnNested: false,
parseOnQuoted: true,
patterns: [decorationRegExp],
}
},
);
4 changes: 2 additions & 2 deletions src/block/node/ExternalLinkNode.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const httpRegExp = /https?:\/\/[^\s]+/;

const createExternalLinkNode: NodeCreator<LinkNode | PlainNode> = (
raw,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
@@ -55,5 +55,5 @@ export const ExternalLinkNodeParser: NodeParser = createNodeParser(
bracketedUrlRegExp,
httpRegExp,
],
}
},
);
4 changes: 2 additions & 2 deletions src/block/node/GoogleMapNode.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const parseCoordinate: (format: string) => Coordinate = (format) => {

const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
raw,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
@@ -45,7 +45,7 @@ const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
const url =
place !== ""
? `https://www.google.com/maps/place/${encodeURIComponent(
place
place,
)}/@${latitude},${longitude},${zoom}z`
: `https://www.google.com/maps/@${latitude},${longitude},${zoom}z`;

5 changes: 4 additions & 1 deletion src/block/node/HelpfeelNode.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,10 @@ import type { NodeCreator } from "./creator";

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

const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (raw, opts) =>
const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (
raw,
opts,
) =>
opts.context === "table"
? createPlainNode(raw, opts)
: [
6 changes: 3 additions & 3 deletions src/block/node/IconNode.ts
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@ import type { NodeCreator } from "./creator";
const iconRegExp = /\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;

export function generateIconNodeCreator(
type: IconNode["type"]
type: IconNode["type"],
): NodeCreator<IconNode>;
export function generateIconNodeCreator(
type: StrongIconNode["type"]
type: StrongIconNode["type"],
): NodeCreator<StrongIconNode | PlainNode>;
export function generateIconNodeCreator(
type: (IconNode | StrongIconNode)["type"]
type: (IconNode | StrongIconNode)["type"],
): NodeCreator<IconNode | StrongIconNode | PlainNode> {
return (raw, opts) => {
if (type === "strongIcon" && opts.context === "table") {
2 changes: 1 addition & 1 deletion src/block/node/NumberListNode.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const numberListRegExp = /^[0-9]+\. .*$/;

const createNumberListNode: NodeCreator<NumberListNode | PlainNode> = (
raw,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
2 changes: 1 addition & 1 deletion src/block/node/StrongImageNode.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ const strongGyazoImageRegExp =

const createStrongImageNode: NodeCreator<StrongImageNode | PlainNode> = (
raw,
opts
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
6 changes: 3 additions & 3 deletions src/block/node/creator.ts
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@ import type { Node } from "./type";

export type NodeCreator<T extends Node> = (
target: string,
opts: NodeParserOption
opts: NodeParserOption,
) => T[];

type NodeParserCreator<T extends Node> = (
nodeCreator: NodeCreator<T>,
opts: { parseOnNested: boolean; parseOnQuoted: boolean; patterns: RegExp[] }
opts: { parseOnNested: boolean; parseOnQuoted: boolean; patterns: RegExp[] },
) => NodeParser;

export const createNodeParser: NodeParserCreator<Node> = (
nodeCreator,
{ parseOnNested, parseOnQuoted, patterns }
{ parseOnNested, parseOnQuoted, patterns },
) => {
return (text, opts, next) => {
if (!parseOnNested && opts.nested) return next?.() ?? [];
6 changes: 3 additions & 3 deletions src/block/node/index.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export type NextNodeParser = () => Node[];
export type NodeParser = (
text: string,
opts: NodeParserOption,
next?: NextNodeParser
next?: NextNodeParser,
) => Node[];

const FalsyEliminator: NodeParser = (text, _, next) => {
@@ -43,7 +43,7 @@ const combineNodeParsers =
(acc: NextNodeParser, parser: NodeParser): NextNodeParser =>
() =>
parser(text, opts, acc),
() => PlainNodeParser(text, opts)
() => PlainNodeParser(text, opts),
)();

export const convertToNodes: ReturnType<typeof combineNodeParsers> =
@@ -65,5 +65,5 @@ export const convertToNodes: ReturnType<typeof combineNodeParsers> =
GoogleMapNodeParser,
InternalLinkNodeParser,
HashTagNodeParser,
NumberListNodeParser
NumberListNodeParser,
);
2 changes: 1 addition & 1 deletion tests/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ expect.extend({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this: any,
received: string,
opts?: ParserOption
opts?: ParserOption,
) {
const blocks = parse(received, opts);
return toMatchSnapshot.call(this, blocks);
Loading