Skip to content

Commit

Permalink
feat(eslint-config): enable the markdown processor
Browse files Browse the repository at this point in the history
This makes sure all markdown snippets are linted as well

Signed-off-by: Dirk de Visser <[email protected]>
  • Loading branch information
dirkdev98 committed May 18, 2024
1 parent e3e02ef commit c12a6a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ This enables environment-specific globals for all files. For a stricter setup, u
configuration as explained below

```js
import { defineConfig } from "@lightbase/eslint-config";
import globals from "globals";
import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
{},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function globAsFormat(glob: string) {
* Apply custom rules to snippets in markdown files.
*/
export function globMarkdownSnippetFromGlob(glob: string) {
return `**/*.md/**/.${glob.split("/").pop() ?? ""}`;
return `**/*.md/**/${glob.split("/").pop() ?? ""}`;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion packages/eslint-config/src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import markdown from "eslint-plugin-markdown";
import typescriptEslint from "typescript-eslint";
import { globMarkdownSnippetFromGlob, GLOBS, globUse } from "./globs.js";

/**
Expand All @@ -12,16 +13,21 @@ export function markdownConfig() {
markdown,
},
},
{
files: globUse([GLOBS.markdown]),
processor: "markdown/markdown",
},
] satisfies Array<FlatConfig.Config>;
}

/**
* Load overrides for Markdown snippets. Is separate, to allow these rules to have priority.
*/
export function markdownSnippetOverrides(): Array<FlatConfig.Config> {
// Disable rules in Markdown snippets

return [
{
// Disable rules in Markdown snippets
files: globUse([
globMarkdownSnippetFromGlob(GLOBS.javascript),
globMarkdownSnippetFromGlob(GLOBS.typescript),
Expand All @@ -30,5 +36,12 @@ export function markdownSnippetOverrides(): Array<FlatConfig.Config> {
"unused-imports/no-unused-vars": "off",
},
},
{
files: globUse([
globMarkdownSnippetFromGlob(GLOBS.javascript),
globMarkdownSnippetFromGlob(GLOBS.typescript),
]),
...typescriptEslint.configs.disableTypeChecked,
},
] satisfies Array<FlatConfig.Config>;
}

0 comments on commit c12a6a8

Please sign in to comment.