Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions docs-svelte-kit/build-system/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ build(
/** build */
function build(input, out, injects = []) {
console.log(`build@ ${input}`)
let code = bundle(input, injects)
code = transform(code, injects)
let code = bundle(input, ["path", ...injects])
code = transform(code, ["path", ...injects])
fs.writeFileSync(out, code, "utf8")
}

Expand All @@ -28,7 +28,7 @@ function bundle(entryPoint, externals) {
entryPoints: [entryPoint],
format: "esm",
bundle: true,
external: ["path", ...externals],
external: externals,
write: false,
})

Expand Down
8 changes: 6 additions & 2 deletions docs-svelte-kit/shim/path.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ function dirname(p) {
return p.split("/").slice(0, -1).join("/") || p
}

const posix = { dirname }
function extname(p) {
return /\.[\w$-]+$/iu.exec(p)[0]
}

const posix = { dirname, extname }
posix.posix = posix
export { dirname, posix }
export { dirname, extname, posix }
export default posix
8 changes: 7 additions & 1 deletion docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script>
import { onMount } from "svelte"
import ESLintEditor from "../eslint/ESLintEditor.svelte"
import { createLinter } from "../eslint/scripts/linter.js"
import {
createLinter,
preprocess,
postprocess,
} from "../eslint/scripts/linter.js"

const linter = createLinter()

Expand All @@ -11,6 +15,8 @@
let time = ""
let options = {
filename: "example.svelte",
preprocess,
postprocess,
}
let showDiff = false

Expand Down
4 changes: 4 additions & 0 deletions docs-svelte-kit/src/lib/components/ESLintPlayground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
DEFAULT_RULES_CONFIG,
getURL,
createLinter,
preprocess,
postprocess,
} from "../eslint/scripts/linter.js"

const linter = createLinter()
Expand Down Expand Up @@ -69,6 +71,8 @@
let time = ""
let options = {
filename: "example.svelte",
preprocess,
postprocess,
}

$: serializedString = (() => {
Expand Down
2 changes: 2 additions & 0 deletions docs-svelte-kit/src/lib/eslint/scripts/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { rules as pluginRules } from "../../../../../src/utils/rules.ts"
import { Linter } from "eslint"
import * as svelteEslintParser from "svelte-eslint-parser"
// eslint-disable-next-line node/file-extension-in-import -- ignore
export { preprocess, postprocess } from "../../../../../src/processor/index.ts"

const linter = new Linter()

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { RuleModule } from "./types"
import { rules as ruleList } from "./utils/rules"
import base from "./configs/base"
import recommended from "./configs/recommended"
import { processor } from "./processor"
import * as processor from "./processor"

const configs = {
base,
Expand Down
37 changes: 19 additions & 18 deletions src/processor/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import type { Linter } from "eslint"
import type { Shared } from "../shared"
import { beginShared, terminateShared } from "../shared"
export const processor = {
preprocess(code: string, filename: string): string[] {
if (filename) {
beginShared(filename)
}

return [code]
},
/** preprocess */
export function preprocess(code: string, filename: string): string[] {
if (filename) {
beginShared(filename)
}

postprocess(
[messages]: Linter.LintMessage[][],
filename: string,
): Linter.LintMessage[] {
const shared = terminateShared(filename)
if (shared) {
return filter(messages, shared)
}
return [code]
}

return messages
},
/** postprocess */
export function postprocess(
[messages]: Linter.LintMessage[][],
filename: string,
): Linter.LintMessage[] {
const shared = terminateShared(filename)
if (shared) {
return filter(messages, shared)
}

supportsAutofix: true,
return messages
}

export const supportsAutofix = true

/** Filter */
function filter(
messages: Linter.LintMessage[],
Expand Down