Skip to content

Commit e56501d

Browse files
committed
feat: 不正言語名抽出
1 parent d7896d9 commit e56501d

File tree

4 files changed

+755
-29
lines changed

4 files changed

+755
-29
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devDependencies": {
1818
"@textlint/types": "^14.4.2",
1919
"@types/node": "^20.17.19",
20+
"textlint": "^14.4.2",
2021
"textlint-scripts": "^14.4.2",
2122
"textlint-tester": "^14.4.2",
2223
"ts-node": "^10.9.2",

src/consts/languages.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const languages: string[] = [
2+
"2html", "a2ps", "a65", "aap", "abap", "abaqus", "abc", "abel", "acedb", "actionscript", "ada", "aflex", "ahdl", "alsaconf", "amiga", "aml", "ampl", "ant", "antlr", "apache", "apachestyle", "applescript", "arch", "art", "asm", "asm68k", "asmh8300", "asn", "aspperl", "aspvbs", "asterisk", "asteriskvm", "atlas", "autohotkey", "autoit", "automake", "ave", "awk", "ayacc",
3+
"baan", "basic", "bc", "bdf", "bib", "bindzone", "blank", "brainfuck", "bst", "btm", "bzr",
4+
"c", "cabal", "calendar", "catalog", "cdl", "cdrdaoconf", "cdrtoc", "cf", "cfg", "ch", "chaiscript", "change", "changelog", "chaskell", "cheetah", "chill", "chordpro", "cl", "clean", "clipper", "clojure", "cmake", "cmusrc", "cobol", "coco", "coffee", "colortest", "conaryrecipe", "conf", "config", "context", "cpp", "crm", "crontab", "crystal", "cs", "csc", "csh", "csp", "css", "cterm", "ctrlh", "cucumber", "cuda", "cupl", "cuplsim", "cvs", "cvsrc", "cweb", "cynlib", "cynpp",
5+
"d", "dart", "dcd", "dcl", "debchangelog", "debcontrol", "debsources", "def", "denyhosts", "desc", "desktop", "dictconf", "dictdconf", "diff", "dircolors", "diva", "django", "dns", "docbk", "docbksgml", "docbkxml", "dosbatch", "dosini", "dot", "doxygen", "dracula", "dsl", "dtd", "dtml", "dtrace", "dylan", "dylanintr", "dylanlid",
6+
"ecd", "edif", "eiffel", "elf", "elinks", "elixir", "elmfilt", "erlang", "eruby", "esmtprc", "esqlc", "esterel", "eterm", "eviews", "exim", "expect", "exports",
7+
"fasm", "fdcc", "fetchmail", "fgl", "flexwiki", "focexec", "form", "forth", "fortran", "foxpro", "framescript", "freebasic", "fsharp", "fstab", "fvwm", "fvwm2m4",
8+
"gdb", "gdmo", "gdresource", "gdscript", "gedcom", "git", "gitcommit", "gitconfig", "gitrebase", "gitsendemail", "gkrellmrc", "glsl", "gnuplot", "go", "gp", "gpg", "grads", "gretl", "groff", "groovy", "group", "grub", "gsl", "gsp", "gtkrc",
9+
"haml", "hamster", "haskell", "haste", "hastepreproc", "hatena", "haxe", "hb", "hcl", "help", "hercules", "hex", "hitest", "hlsl", "hog", "hostconf", "hss", "html", "htmlcheetah", "htmldjango", "htmlm4", "htmlos", "hxml",
10+
"ia64", "ibasic", "icemenu", "icon", "idl", "idlang", "indent", "inform", "initex", "initng", "inittab", "io", "ipfilter", "ishd", "iss", "ist",
11+
"jal", "jam", "jargon", "java", "javacc", "javascript", "jess", "jgraph", "jproperties", "json", "jsp", "jsx", "julia",
12+
"kconfig", "kix", "kotlin", "kscript", "kwt",
13+
"lace", "latte", "ld", "ldapconf", "ldif", "lex", "lftp", "lhaskell", "libao", "lifelines", "lilo", "limits", "lisp", "lite", "litestep", "loginaccess", "logindefs", "logtalk", "lotos", "lout", "lpc", "lprolog", "lscript", "lsl", "lss", "lua", "lynx",
14+
"m4", "mail", "mailaliases", "mailcap", "make", "man", "manconf", "manual", "maple", "markdown", "masm", "mason", "master", "matlab", "maxima", "mel", "messages", "mf", "mgl", "mgp", "mib", "mma", "mmix", "mmp", "modconf", "model", "modsim3", "modula2", "modula3", "monk", "moo", "mp", "mplayerconf", "mrxvtrc", "msidl", "msmessages", "msql", "mupad", "mush", "muttrc", "mysql",
15+
"named", "nanorc", "nasm", "nastran", "natural", "ncf", "netrc", "netrw", "nginx", "nim", "nosyntax", "nqc", "nroff", "nsis",
16+
"obj", "objc", "objcpp", "ocaml", "occam", "omnimark", "openroad", "opl", "ora",
17+
"pamconf", "papp", "pascal", "passwd", "pcap", "pccts", "pdf", "perl", "perl6", "pf", "pfmain", "php", "phtml", "pic", "pike", "pilrc", "pine", "pinfo", "plaintex", "plm", "plp", "plsql", "po", "pod", "postscr", "pov", "povini", "ppd", "ppwiz", "prescribe", "privoxy", "processing", "procmail", "progress", "prolog", "promela", "proto", "protocols", "ps1", "ps1xml", "psf", "ptcap", "purifylog", "pyrex", "python",
18+
"qf", "quake",
19+
"r", "racc", "radiance", "ratpoison", "rc", "rcs", "rcslog", "readline", "rebol", "registry", "remind", "resolv", "reva", "rexx", "rhelp", "rib", "rnc", "rnoweb", "robots", "rpcgen", "rpl", "rst", "rtf", "ruby", "rust",
20+
"samba", "sas", "sass", "sather", "scala", "scheme", "scilab", "screen", "sd", "sdc", "sdl", "sed", "sendpr", "sensors", "services", "setserial", "sgml", "sgmldecl", "sgmllnx", "sh", "sicad", "sieve", "simula", "sinda", "sindacmp", "sindaout", "sisu", "skill", "sl", "slang", "slice", "slpconf", "slpreg", "slpspi", "slrnrc", "slrnsc", "sm", "smarty", "smcl", "smil", "smith", "sml", "snnsnet", "snnspat", "snnsres", "snobol4", "spec", "specman", "spice", "splint", "spup", "spyce", "sql", "sqlanywhere", "sqlforms", "sqlinformix", "sqlj", "sqloracle", "sqr", "squid", "sshconfig", "sshdconfig", "st", "stata", "stp", "strace", "sudoers", "svg", "svn", "swift", "syncolor", "synload", "syntax", "sysctl",
21+
"tads", "tags", "tak", "takcmp", "takout", "tar", "taskdata", "taskedit", "tasm", "tcl", "tcsh", "terminfo", "terraform", "tex", "texinfo", "texmf", "tf", "tidy", "tilde", "tli", "tpp", "trasys", "trustees", "tsalt", "tsscl", "tssgm", "tssop", "tsx", "typescript",
22+
"uc", "udevconf", "udevperm", "udevrules", "uil", "updatedb",
23+
"valgrind", "vb", "vera", "verilog", "verilogams", "vgrindefs", "vhdl", "vim", "viminfo", "virata", "vmasm", "voscm", "vrml", "vsejcl",
24+
"wdiff", "web", "webmacro", "wget", "whitespace", "winbatch", "wml", "wsh", "wsml", "wvdial",
25+
"xbl", "xdefaults", "xf86conf", "xhtml", "xinetd", "xkb", "xmath", "xml", "xmodmap", "xpm", "xpm2", "xquery", "xs", "xsd", "xslt", "xxd",
26+
"yacc", "yaml",
27+
"z8a", "zig", "zir", "zsh"
28+
];

src/index.ts

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
import type { TextlintRuleModule } from "@textlint/types";
2+
import { languages } from "./consts/languages";
23

3-
export interface Options {
4-
// If node's text includes allowed text, does not report.
5-
allows?: string[];
6-
}
7-
8-
const report: TextlintRuleModule<Options> = (context, options = {}) => {
9-
const { Syntax, RuleError, report, getSource, locator } = context;
10-
const allows = options.allows ?? [];
4+
const report: TextlintRuleModule = (context) => {
5+
const { Syntax, RuleError, report } = context;
116
return {
12-
[Syntax.Str](node) { // "Str" node
13-
const text = getSource(node); // Get text
14-
if (allows.some(allow => text.includes(allow))) {
15-
return;
16-
}
17-
const matches = text.matchAll(/bugs/g);
18-
for (const match of matches) {
19-
const index = match.index ?? 0;
20-
const matchRange = [index, index + match[0].length] as const;
21-
const ruleError = new RuleError("Found bugs.", {
22-
padding: locator.range(matchRange)
23-
});
7+
[Syntax.CodeBlock](node) {
8+
const lang = node.lang || '';
9+
if (!languages.includes(lang)) {
10+
const ruleError = new RuleError(`不正なシンタックスハイライトのファイルタイプが見つかりました。:${lang}`);
2411
report(node, ruleError);
2512
}
2613
}

0 commit comments

Comments
 (0)