-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move getShortLang outside markdown processor (#291)
- Loading branch information
Showing
11 changed files
with
131 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { last } from 'eslint-mdx' | ||
|
||
export const DEFAULT_LANGUAGE_MAPPER: Record<string, string> = { | ||
javascript: 'js', | ||
javascriptreact: 'jsx', | ||
typescript: 'ts', | ||
typescriptreact: 'tsx', | ||
markdown: 'md', | ||
mdown: 'md', | ||
mkdn: 'md', | ||
} | ||
|
||
export function getShortLang( | ||
filename: string, | ||
languageMapper?: false | Record<string, string>, | ||
): string { | ||
const language = last(filename.split('.')) | ||
if (languageMapper === false) { | ||
return language | ||
} | ||
languageMapper = { ...DEFAULT_LANGUAGE_MAPPER, ...languageMapper } | ||
const lang = language.toLowerCase() | ||
return languageMapper[language] || languageMapper[lang] || lang | ||
} |
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
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,18 +1,28 @@ | ||
import type { Linter } from 'eslint' | ||
|
||
export interface ESLinterProcessorFile { | ||
text: string | ||
filename: string | ||
} | ||
|
||
// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins | ||
export interface ESLintProcessor { | ||
export interface ESLintProcessor< | ||
T extends string | ESLinterProcessorFile = string | ESLinterProcessorFile | ||
> { | ||
supportsAutofix?: boolean | ||
preprocess?( | ||
text: string, | ||
filename: string, | ||
): Array<string | { text: string; filename: string }> | ||
preprocess?(text: string, filename: string): T[] | ||
postprocess?( | ||
messages: Linter.LintMessage[][], | ||
filename: string, | ||
): Linter.LintMessage[] | ||
} | ||
|
||
export interface ESLintMdxSettings { | ||
'mdx/code-blocks': boolean | ||
'mdx/language-mapper'?: false | Record<string, string> | ||
} | ||
|
||
export interface ProcessorOptions { | ||
lintCodeBlocks: boolean | ||
languageMapper?: false | Record<string, string> | ||
} |
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
Oops, something went wrong.