From 2839c459e1c5543407383a743dbc383db9e83505 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sun, 8 Aug 2021 14:57:15 +0700 Subject: [PATCH] refactor: convert to typescript --- .editorconfig | 4 + .eslintrc.json | 21 + .gitignore | 119 +- .husky/pre-commit | 4 + .nvmrc | 1 + .prettierrc | 10 + .travis.yml | 9 - LICENSE | 1 + index.js | 414 - package-lock.json | 3871 ++++++++ package.json | 30 +- prepare.cjs | 12 + src/index.ts | 137 + src/languages/c.ts | 36 + src/languages/cpp.ts | 40 + src/languages/css.ts | 8 + src/languages/go.ts | 26 + src/languages/html.ts | 11 + src/languages/java.ts | 44 + src/languages/javascript.ts | 32 + src/languages/php.ts | 32 + src/languages/python.ts | 28 + src/languages/ruby.ts | 30 + test/site/bundle.js | 11167 ---------------------- {test => tests}/fizzbuzz/fizzbuzz.c | 0 {test => tests}/fizzbuzz/fizzbuzz.cpp | 0 {test => tests}/fizzbuzz/fizzbuzz.go | 0 {test => tests}/fizzbuzz/fizzbuzz.java | 0 {test => tests}/fizzbuzz/fizzbuzz.js | 0 {test => tests}/fizzbuzz/fizzbuzz.php | 0 {test => tests}/fizzbuzz/fizzbuzz.py | 0 {test => tests}/fizzbuzz/fizzbuzz.rb | 0 {test => tests}/random/large.c | 0 {test => tests}/random/normalize.css | 0 {test => tests}/random/page.html | 0 tests/site/bundle.js | 11170 +++++++++++++++++++++++ {test => tests}/site/main.js | 0 {test => tests}/site/test.html | 0 {test => tests}/test.js | 0 webpack.config.js | 12 - 40 files changed, 15652 insertions(+), 11617 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.json create mode 100644 .husky/pre-commit create mode 100644 .nvmrc create mode 100644 .prettierrc delete mode 100644 .travis.yml delete mode 100644 index.js create mode 100644 package-lock.json create mode 100644 prepare.cjs create mode 100644 src/index.ts create mode 100644 src/languages/c.ts create mode 100644 src/languages/cpp.ts create mode 100644 src/languages/css.ts create mode 100644 src/languages/go.ts create mode 100644 src/languages/html.ts create mode 100644 src/languages/java.ts create mode 100644 src/languages/javascript.ts create mode 100644 src/languages/php.ts create mode 100644 src/languages/python.ts create mode 100644 src/languages/ruby.ts delete mode 100644 test/site/bundle.js rename {test => tests}/fizzbuzz/fizzbuzz.c (100%) rename {test => tests}/fizzbuzz/fizzbuzz.cpp (100%) rename {test => tests}/fizzbuzz/fizzbuzz.go (100%) rename {test => tests}/fizzbuzz/fizzbuzz.java (100%) rename {test => tests}/fizzbuzz/fizzbuzz.js (100%) rename {test => tests}/fizzbuzz/fizzbuzz.php (100%) rename {test => tests}/fizzbuzz/fizzbuzz.py (100%) rename {test => tests}/fizzbuzz/fizzbuzz.rb (100%) rename {test => tests}/random/large.c (100%) rename {test => tests}/random/normalize.css (100%) rename {test => tests}/random/page.html (100%) create mode 100644 tests/site/bundle.js rename {test => tests}/site/main.js (100%) rename {test => tests}/site/test.html (100%) rename {test => tests}/test.js (100%) delete mode 100644 webpack.config.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f827fc4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*] +indent_style = space +indent_size = 2 +end_of_line=lf \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..c3c0a7e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "env": { + "browser": true, + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + } +} diff --git a/.gitignore b/.gitignore index 472806a..0125458 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,118 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* -/node_modules -/npm-debug.log +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env.production + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..18af3ef --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run lint && npm run format \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..6e52078 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v16.6.1 diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0aecf9b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "useTabs": false, + "endOfLine": "lf", + "arrowParens": "always", + "semi": true, + "tabWidth": 2, + "singleQuote": true, + "trailingComma": "all", + "printWidth": 120 +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6b4bb81..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -cache: - directories: - - node_modules -node_js: - - "6" - - "5" - - "4" - diff --git a/LICENSE b/LICENSE index 1ff3cff..e60e8f5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015 Toni Sučić +Copyright (c) 2021 Teknologi Umum Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/index.js b/index.js deleted file mode 100644 index 806ecf7..0000000 --- a/index.js +++ /dev/null @@ -1,414 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2015 Toni Sučić - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -var _ = require('underscore'); - -/** - * A checker is an object with the following form: - * { pattern: /something/, points: 1 } - * or if the pattern only matches code near the top of a given file: - * { pattern: /something/, points: 2, nearTop: true } - * - * Key: Language name. - * Value: Array of checkers. - * - * N.B. An array of checkers shouldn't contain more regexes than - * necessary as it would inhibit performance. - * - * Points scale: - * 2 = Bonus points: Almost unique to a given language. - * 1 = Regular point: Not unique to a given language. - * -1 = Penalty point: Does not match a given language. - * Rare: - * -50 = Bonus penalty points: Only used when two languages are mixed together, - * and one has a higher precedence over the other one. - */ -var languages = { - 'JavaScript': [ - // undefined keyword - { pattern: /undefined/g, points: 2 }, - // console.log('ayy lmao') - { pattern: /console\.log( )*\(/, points: 2 }, - // Variable declaration - { pattern: /(var|const|let)( )+\w+( )*=?/, points: 2 }, - // Array/Object declaration - { pattern: /(('|").+('|")( )*|\w+):( )*[{\[]/, points: 2 }, - // === operator - { pattern: /===/g, points: 1 }, - // !== operator - { pattern: /!==/g, points: 1 }, - // Function definition - { pattern: /function\*?(( )+[\$\w]+( )*\(.*\)|( )*\(.*\))/g, points: 1 }, - // null keyword - { pattern: /null/g, points: 1 }, - // lambda expression - { pattern: /\(.*\)( )*=>( )*.+/, points: 1 }, - // (else )if statement - { pattern: /(else )?if( )+\(.+\)/, points: 1 }, - // while loop - { pattern: /while( )+\(.+\)/, points: 1 }, - // C style variable declaration. - { pattern: /(^|\s)(char|long|int|float|double)( )+\w+( )*=?/, points: -1 }, - // pointer - { pattern: /(\w+)( )*\*( )*\w+/, points: -1 }, - // HTML