-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
583 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,3 +115,5 @@ dist | |
/playground | ||
/rules | ||
/user-guide | ||
/docs/.vitepress/cache | ||
/docs/.vitepress/build-system/shim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
rules: { | ||
"require-jsdoc": "off", | ||
"n/file-extension-in-import": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Pre-build cjs packages that cannot be bundled well. | ||
*/ | ||
import esbuild from "esbuild"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { fileURLToPath } from "url"; | ||
|
||
const dirname = path.dirname( | ||
fileURLToPath( | ||
// @ts-expect-error -- Cannot change `module` option | ||
import.meta.url, | ||
), | ||
); | ||
|
||
build( | ||
path.join(dirname, "./src/vue-eslint-parser.mjs"), | ||
path.join(dirname, "./shim/vue-eslint-parser.mjs"), | ||
["eslint", "path", "module", "events"], | ||
); | ||
build( | ||
path.join(dirname, "./src/events.mjs"), | ||
path.join(dirname, "./shim/events.mjs"), | ||
[], | ||
); | ||
|
||
function build(input: string, out: string, injects: string[] = []) { | ||
// eslint-disable-next-line no-console -- ignore | ||
console.log(`build@ ${input}`); | ||
let code = bundle(input, injects); | ||
code = transform(code, injects); | ||
fs.mkdirSync(path.dirname(out), { recursive: true }); | ||
fs.writeFileSync(out, code, "utf8"); | ||
} | ||
|
||
function bundle(entryPoint: string, externals: string[]) { | ||
const result = esbuild.buildSync({ | ||
entryPoints: [entryPoint], | ||
format: "esm", | ||
bundle: true, | ||
external: externals, | ||
write: false, | ||
}); | ||
|
||
return `${result.outputFiles[0].text}`; | ||
} | ||
|
||
function transform(code: string, injects: string[]) { | ||
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, ""); | ||
return ` | ||
${injects | ||
.map( | ||
(inject) => | ||
`import $inject_${inject.replace(/-/gu, "_")}$ from '${inject}';`, | ||
) | ||
.join("\n")} | ||
const $_injects_$ = {${injects | ||
.map((inject) => `${inject.replace(/-/gu, "_")}:$inject_${inject}$`) | ||
.join(",\n")}}; | ||
function require(module, ...args) { | ||
return $_injects_$[module] || {} | ||
} | ||
${newCode} | ||
if (typeof __require !== 'undefined') __require.cache = {}; | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import all from "events"; | ||
export default all; | ||
export const EventEmitter = all.EventEmitter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import all from "vue-eslint-parser"; | ||
export default all; | ||
export const parseForESLint = all.parseForESLint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import type { DefaultTheme, UserConfig } from "vitepress"; | ||
import { defineConfig } from "vitepress"; | ||
import { BUNDLED_LANGUAGES } from "shiki"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import eslint4b from "vite-plugin-eslint4b"; | ||
import type { RuleModule } from "../../lib/types.js"; | ||
import { viteCommonjs, vitePluginAutoRule } from "./vite-plugin.mjs"; | ||
|
||
import "./build-system/build.js"; | ||
const dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
// Include `json5` as alias for jsonc | ||
const jsonc = BUNDLED_LANGUAGES.find((lang) => lang.id === "jsonc"); | ||
if (jsonc) jsonc.aliases = [...(jsonc?.aliases ?? []), "json5"]; | ||
|
||
function ruleToSidebarItem({ | ||
meta: { | ||
docs: { ruleId, ruleName }, | ||
}, | ||
}: RuleModule): DefaultTheme.SidebarItem { | ||
return { | ||
text: ruleId, | ||
link: `/rules/${ruleName}`, | ||
}; | ||
} | ||
|
||
export default async (): Promise<UserConfig<DefaultTheme.Config>> => { | ||
const a = "../../dist/utils/rules.js"; | ||
const { rules } = (await import(a)) as { rules: RuleModule[] }; | ||
return defineConfig({ | ||
base: "/eslint-plugin-jsonc/", | ||
title: "eslint-plugin-jsonc", | ||
outDir: path.join(dirname, "./dist/eslint-plugin-jsonc"), | ||
description: | ||
"ESLint plugin for finding RegExp mistakes and RegExp style guide violations.", | ||
head: [ | ||
[ | ||
"link", | ||
{ | ||
rel: "icon", | ||
href: "/eslint-plugin-jsonc/logo.svg", | ||
type: "image/svg+xml", | ||
}, | ||
], | ||
], | ||
|
||
vite: { | ||
plugins: [viteCommonjs(), vitePluginAutoRule(), eslint4b()], | ||
resolve: { | ||
alias: { | ||
"vue-eslint-parser": path.join( | ||
dirname, | ||
"./build-system/shim/vue-eslint-parser.mjs", | ||
), | ||
module: path.join(dirname, "./shim/module.mjs"), | ||
events: path.join(dirname, "./build-system/shim/events.mjs"), | ||
}, | ||
}, | ||
define: { | ||
"process.env.NODE_DEBUG": "false", | ||
}, | ||
optimizeDeps: { | ||
// exclude: ["vue-eslint-parser"], | ||
}, | ||
}, | ||
|
||
lastUpdated: true, | ||
themeConfig: { | ||
logo: "/logo.svg", | ||
search: { | ||
provider: "local", | ||
options: { | ||
detailedView: true, | ||
}, | ||
}, | ||
editLink: { | ||
pattern: | ||
"https://github.com/ota-meshi/eslint-plugin-jsonc/edit/master/docs/:path", | ||
}, | ||
nav: [ | ||
{ text: "Introduction", link: "/" }, | ||
{ text: "User Guide", link: "/user-guide/" }, | ||
{ text: "Rules", link: "/rules/" }, | ||
{ text: "Playground", link: "/playground/" }, | ||
], | ||
socialLinks: [ | ||
{ | ||
icon: "github", | ||
link: "https://github.com/ota-meshi/eslint-plugin-jsonc", | ||
}, | ||
], | ||
sidebar: { | ||
"/rules/": [ | ||
{ | ||
text: "Rules", | ||
items: [{ text: "Available Rules", link: "/rules/" }], | ||
}, | ||
{ | ||
text: "JSONC Rules", | ||
collapsed: false, | ||
items: rules | ||
.filter( | ||
(rule) => | ||
!rule.meta.docs.extensionRule && !rule.meta.deprecated, | ||
) | ||
.map(ruleToSidebarItem), | ||
}, | ||
{ | ||
text: "Extension Rules", | ||
collapsed: false, | ||
items: rules | ||
.filter( | ||
(rule) => rule.meta.docs.extensionRule && !rule.meta.deprecated, | ||
) | ||
.map(ruleToSidebarItem), | ||
}, | ||
|
||
// Rules in no category. | ||
...(rules.some((rule) => rule.meta.deprecated) | ||
? [ | ||
{ | ||
text: "Deprecated", | ||
collapsed: false, | ||
items: rules | ||
.filter((rule) => rule.meta.deprecated) | ||
.map(ruleToSidebarItem), | ||
}, | ||
] | ||
: []), | ||
], | ||
"/": [ | ||
{ | ||
text: "Guide", | ||
items: [ | ||
{ text: "Introduction", link: "/" }, | ||
{ text: "User Guide", link: "/user-guide/" }, | ||
{ text: "Rules", link: "/rules/" }, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function createRequire() { | ||
// noop | ||
} | ||
export default { | ||
createRequire, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// eslint-disable-next-line n/no-missing-import -- The file path used is the actual rule path | ||
import { createRule } from "../utils"; | ||
export default createRule("auto", { | ||
meta: { | ||
docs: { | ||
description: | ||
"apply jsonc rules similar to your configured ESLint core rules", | ||
recommended: null, | ||
extensionRule: false, | ||
layout: false, | ||
}, | ||
fixable: "code", | ||
schema: [], | ||
messages: {}, | ||
type: "suggestion", | ||
}, | ||
create(context) { | ||
if (!context.parserServices.isJSON) { | ||
return {}; | ||
} | ||
context.report({ | ||
node: context.getSourceCode().ast, | ||
loc: { | ||
line: 1, | ||
column: 0, | ||
}, | ||
message: "The `auto` rule does not work in browsers.", | ||
}); | ||
return {}; | ||
}, | ||
}); |
5 changes: 4 additions & 1 deletion
5
docs/.vuepress/styles/stylelint.config.js → docs/.vitepress/stylelint.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
module.exports = { | ||
extends: ["stylelint-config-standard", "stylelint-stylus/standard"], | ||
extends: ["stylelint-config-standard-vue"], | ||
rules: { | ||
"no-descending-specificity": null, | ||
"selector-class-pattern": null, | ||
"value-keyword-case": null, | ||
|
||
// Conflict with Prettier | ||
indentation: null, | ||
}, | ||
}; |
Oops, something went wrong.