Last active
March 8, 2019 20:52
-
-
Save kanaka/10ca021e355b2bdf2cab9503bfe95623 to your computer and use it in GitHub Desktop.
Filter loccount output to show misidentified mal files
This file contains hidden or 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
#!/usr/bin/env node | |
const VERBOSE = process.argv.indexOf('-v') > 0 | |
const fs = require('fs') | |
const re_ignore = /^$|^[^\/]+ |^docs\/|^tests\/|\.css CSS|\.h C-header|\.md Markdown/ | |
//const re_ignore = /^$|^[^\/]+ |^docs\/|^tests\// | |
const re_loc = /([^\/]+)\/([^ ]+) ([^ ]+) ([0-9]+) ([0-9]+)/ | |
const lines = fs.readFileSync(0, 'utf-8').split('\n') | |
// implementation directory to file type mapping | |
const impl_kind = { | |
'bash': 'shell', | |
'common-lisp': 'Lisp', | |
'cs': 'C#', | |
'cpp': 'C++', | |
'es6': 'Javascript', | |
'fsharp': 'F#', | |
'guile': 'Scheme', | |
'js': 'Javascript', | |
'make': 'makefile', | |
'miniMAL': 'JSON', | |
'nasm': 'asm', | |
'objc': 'Objective-C', | |
'objpascal': 'Pascal', | |
'ocaml': 'ML', | |
'perl6': 'Perl', | |
'picolisp': 'Lisp', | |
'plpgsql': 'SQL', | |
'plsql': 'SQL', | |
'rpython': 'Python', | |
'swift3': 'Swift', | |
'swift4': 'Swift', | |
'ts': 'Typescript', | |
} | |
// files that occur in multiple implementations and are a different | |
// type from the implementation directory | |
const file_kind = { | |
'Makefile': 'makefile', | |
'run': 'shell', | |
'package.json': 'JSON', | |
'node_readline.js': 'Javascript', | |
} | |
// specific files paths that are a different type from the | |
// implementation directory | |
const path_kind = { | |
'basic/basicpp.py': 'Python', | |
'clojure/src/mal/node_readline.js': 'Javascript', | |
'clojure/src/mal/readline.cljs': 'Clojurescript', | |
'cpp/docker.sh': 'shell', | |
'dart/pubspec.yaml': 'YAML', | |
'elm/bootstrap.js': 'Javascript', | |
'elm/elm-package.json': 'JSON', | |
'fsharp/terminal.cs': 'C#', | |
'java/pom.xml': 'XML', | |
'objc/mal_readline.c': 'C', | |
'plpgsql/entrypoint.sh': 'shell', | |
'plpgsql/wrap.sh': 'shell', | |
'plsql/entrypoint.sh': 'shell', | |
'plsql/wrap.sh': 'shell', | |
'process/cheatsheet.html': 'HTML', | |
'rust/Cargo.toml': 'TOML', | |
'swift/templates/add_steps.sh': 'shell', | |
'swift/templates/filter_steps.sh': 'shell', | |
'ts/tsconfig.json': 'JSON', | |
'vb/getline.cs': 'C#', | |
'vhdl/run_vhdl.sh': 'shell', | |
'vimscript/run_vimscript.sh': 'shell', | |
'vimscript/vimextras.c': 'C', | |
'wasm/run.js': 'Javascript', | |
} | |
const vlog = (...a) => VERBOSE ? console.log(...a) : null | |
for (let line of lines) { | |
if (re_ignore.exec(line)) { | |
vlog(`IGNORE: ${line}`) | |
continue | |
} | |
const [match, impl, file, kind, sloc, lloc] = re_loc.exec(line) | |
if (impl === kind.toLowerCase()) { | |
vlog(`GOOD: ${impl}/${file} (${kind})`) | |
} else if (impl_kind[impl] === kind) { | |
vlog(`GOOD: ${impl}/${file} (${kind})`) | |
} else if (file_kind[file] === kind) { | |
vlog(`GOOD: ${impl}/${file} (${kind})`) | |
} else if (path_kind[impl+"/"+file] === kind) { | |
vlog(`GOOD: ${impl}/${file} (${kind})`) | |
} else { | |
console.warn("UNKNOWN:", impl, file, kind, sloc, lloc) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment