-
Notifications
You must be signed in to change notification settings - Fork 5
feat: migration to typescript (wip) #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| @blackflux/robo-config-plugin | ||
| @tsconfig/node14 | ||
| ts-loader | ||
| ts-node | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these all needed? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| .c8rc.json | ||
| .circleci/config.yml | ||
| .dependabot/config.yml | ||
| .eslintrc.json | ||
| .gally.json | ||
| .mocharc.yml | ||
| .releaserc.json | ||
| .roboconfig.json | ||
| CONFDOCS.md | ||
| gardener.js | ||
| package.json | ||
| README.md | ||
| src/assert.ts | ||
| src/index.ts | ||
| test/assert.spec.ts | ||
| test/eslint.spec.ts | ||
| test/hot.js | ||
| test/index.spec.ts | ||
| tsconfig.eslint.json | ||
| tsconfig.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,75 @@ | ||
| { | ||
| "root": true, | ||
| "extends": [ | ||
| "airbnb-base", | ||
| "plugin:mocha/recommended", | ||
| "plugin:markdown/recommended" | ||
| ], | ||
| "rules": { | ||
| "@blackflux/rules/c8-prevent-ignore": 1, | ||
| "@blackflux/rules/kebab-case-enforce": 1, | ||
| "max-len": ["error", {"code": 120}], | ||
| "mocha/no-exclusive-tests": "error", | ||
| "prefer-destructuring": ["error", {"object": false, "array": false}], | ||
| "comma-dangle": ["error", "never"], | ||
| "indent": ["error", 2, {"SwitchCase": 1}], | ||
| "quotes": [2, "single", {"avoidEscape": true}], | ||
| "linebreak-style": [2, "unix"], | ||
| "semi": [2, "always"], | ||
| "no-unused-vars": [ | ||
| 1, | ||
| {"vars": "all", "args": "none", "ignoreRestSiblings": true} | ||
| ], | ||
| "no-var": [1], | ||
| "no-fallthrough": [1], | ||
| "spaced-comment": [ | ||
| "error", | ||
| "always", | ||
| { | ||
| "line": {"exceptions": ["-", "+"], "markers": ["=", "!"]}, | ||
| "block": { | ||
| "exceptions": ["-", "+"], | ||
| "markers": ["=", "!", ":", "::"], | ||
| "balanced": true | ||
| } | ||
| } | ||
| ], | ||
| "@blackflux/rules/prevent-typeof-object": 1, | ||
| "mocha/no-mocha-arrows": 0, | ||
| "mocha/no-hooks-for-single-case": 0, | ||
| "import/no-useless-path-segments": [2, {"commonjs": true}], | ||
| "import/extensions": [2, "always"], | ||
| "import/prefer-default-export": 0 | ||
| }, | ||
| "env": {"es6": true, "node": true, "mocha": true}, | ||
| "globals": {}, | ||
| "plugins": ["json", "mocha", "@blackflux/rules"], | ||
| "parser": "@babel/eslint-parser", | ||
| "parserOptions": {"requireConfigFile": false} | ||
| "parserOptions": {"requireConfigFile": false}, | ||
| "overrides": [ | ||
| { | ||
| "files": ["*.js", "*.cjs", "*.mjs"], | ||
| "extends": ["airbnb-base", "plugin:mocha/recommended", "plugin:markdown/recommended"], | ||
| "plugins": ["mocha", "@blackflux/rules"] | ||
| }, | ||
| { | ||
| "files": ["*.ts", "*.tsx"], | ||
| "extends": ["airbnb-base", "plugin:mocha/recommended", "plugin:markdown/recommended", "airbnb-typescript/base"], | ||
| "plugins": ["mocha", "@blackflux/rules", "@typescript-eslint"], | ||
| "parser": "@typescript-eslint/parser", | ||
| "parserOptions": {"project": "./tsconfig.eslint.json"} | ||
| }, | ||
| { | ||
| "files": ["*.js", "*.cjs", "*.mjs", "*.ts", "*.tsx"], | ||
| "rules": { | ||
| "@blackflux/rules/c8-prevent-ignore": 1, | ||
| "@blackflux/rules/kebab-case-enforce": 1, | ||
| "max-len": ["error", {"code": 120}], | ||
| "mocha/no-exclusive-tests": "error", | ||
| "prefer-destructuring": ["error", {"object": false, "array": false}], | ||
| "comma-dangle": ["error", "never"], | ||
| "@typescript-eslint/comma-dangle": ["error", "never"], | ||
| "indent": ["error", 2, {"SwitchCase": 1}], | ||
| "quotes": [2, "single", {"avoidEscape": true}], | ||
| "linebreak-style": [2, "unix"], | ||
| "semi": [2, "always"], | ||
| "no-unused-vars": [ | ||
| 1, | ||
| {"vars": "all", "args": "none", "ignoreRestSiblings": true} | ||
| ], | ||
| "no-var": [1], | ||
| "no-fallthrough": [1], | ||
| "spaced-comment": [ | ||
| "error", | ||
| "always", | ||
| { | ||
| "line": {"exceptions": ["-", "+"], "markers": ["=", "!"]}, | ||
| "block": { | ||
| "exceptions": ["-", "+"], | ||
| "markers": ["=", "!", ":", "::"], | ||
| "balanced": true | ||
| } | ||
| } | ||
| ], | ||
| "@blackflux/rules/prevent-typeof-object": 1, | ||
| "mocha/no-mocha-arrows": 0, | ||
| "mocha/no-hooks-for-single-case": 0, | ||
| "import/no-useless-path-segments": [2, {"commonjs": true}], | ||
| "import/extensions": [2, "always"], | ||
| "import/prefer-default-export": 0 | ||
| } | ||
| }, | ||
| { | ||
| "files": ["*.md"], | ||
| "plugins": ["markdown"], | ||
| "processor": "markdown/markdown" | ||
| }, | ||
| { | ||
| "files": ["*.yaml", "*.yml"], | ||
| "plugins": ["yaml"], | ||
| "extends": ["plugin:yaml/recommended"] | ||
| }, | ||
| { | ||
| "files": ["*.json"], | ||
| "plugins": ["json"] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| timeout: 2000 | ||
| node-option: | ||
| - experimental-specifier-resolution=node | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? |
||
| - loader=ts-node/esm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,10 @@ | |
| "main": "lib/index.js", | ||
| "scripts": { | ||
| "clean": "rm -rf lib", | ||
| "build": "cp -rf ./src ./lib && ncc build -m -o lib && mv lib/index.js lib/index.min.js && cp src/index.js lib/index.js && rm lib/package.json", | ||
| "compile": "tsc -p tsconfig.json", | ||
| "build": "cp -rf ./src ./lib && ncc build -m -o lib && mv lib/index.ts lib/index.min.ts && mv lib/index.js lib/index.min.js && cp src/index.ts lib/index.ts && rm lib/package.json", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need build and compile? What is the difference? |
||
| "build-clean": "yarn run clean && yarn run build", | ||
| "test-simple": "c8 mocha --experimental-loader=./test/hot.js \"./test/**/*.spec.js\"", | ||
| "test-simple": "c8 mocha --experimental-loader=./test/hot.js \"./test/**/*.spec.ts\"", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this include all file extensions? |
||
| "test": "yarn run clean && yarn run gardener && yarn run test-simple", | ||
| "semantic-release": "yarn run build-clean && npx semantic-release", | ||
| "gardener": "node gardener.js", | ||
|
|
@@ -48,20 +49,33 @@ | |
| "@babel/core": "7.18.10", | ||
| "@babel/eslint-parser": "7.18.9", | ||
| "@babel/register": "7.18.9", | ||
| "@blackflux/eslint-plugin-rules": "2.2.0", | ||
| "@blackflux/eslint-plugin-rules": "2.1.0", | ||
| "@blackflux/robo-config-plugin": "7.9.11", | ||
| "@tsconfig/node14": "1.0.3", | ||
| "@types/chai": "4.3.3", | ||
| "@types/mocha": "9.1.1", | ||
| "@typescript-eslint/eslint-plugin": "5.37.0", | ||
| "@typescript-eslint/parser": "5.37.0", | ||
| "@vercel/ncc": "0.34.0", | ||
| "c8": "7.12.0", | ||
| "chai": "4.3.6", | ||
| "eslint": "8.22.0", | ||
| "eslint-config-airbnb-base": "15.0.0", | ||
| "eslint-config-airbnb-typescript": "17.0.0", | ||
| "eslint-plugin-import": "2.26.0", | ||
| "eslint-plugin-json": "3.1.0", | ||
| "eslint-plugin-markdown": "3.0.0", | ||
| "eslint-plugin-mocha": "10.1.0", | ||
| "js-gardener": "4.0.1", | ||
| "eslint-plugin-yaml": "0.5.0", | ||
| "glob": "8.0.3", | ||
| "js-gardener": "4.0.2", | ||
| "node-tdd": "3.4.3", | ||
| "plugin-name-to-package-name": "0.1.1", | ||
| "smart-fs": "3.0.1", | ||
| "treeify": "1.1.0" | ||
| "treeify": "1.1.0", | ||
| "ts-loader": "9.3.1", | ||
| "ts-node": "10.9.1", | ||
| "typescript": "4.7.4" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these deps required? |
||
| }, | ||
| "licenses": [ | ||
| { | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export default (condition : boolean, message : string) => { | ||
| if (!condition) { | ||
| throw new Error(message); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // @ts-ignore | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Way too many ts-ignore here. How can we get rid of all / most? |
||
| import { expect } from 'chai'; | ||
| // @ts-ignore | ||
| import fs from 'smart-fs'; | ||
| // @ts-ignore | ||
| import path from 'path'; | ||
| // @ts-ignore | ||
| import { ESLint } from 'eslint'; | ||
| import { transform } from 'plugin-name-to-package-name'; | ||
| // @ts-ignore | ||
| import glob from 'glob'; | ||
| // @ts-ignore | ||
| import { describe } from 'node-tdd'; | ||
|
|
||
| const globSync = glob.sync; | ||
|
|
||
| describe('Testing eslint', { timeout: 10000 }, () => { | ||
| it('Linting files', async () => { | ||
| // @ts-ignore | ||
| const dir = path.join(fs.dirname(import.meta.url), '..'); | ||
| const files = globSync( | ||
| '**/*.{ts,tsx,js,cjs,mjs,md,yaml,yml,json}', | ||
| { | ||
| cwd: dir, | ||
| ignore: fs.smartRead(path.join(dir, 'tsconfig.eslint.json')).exclude, | ||
| dot: true | ||
| } | ||
| ); | ||
| const config = fs.smartRead(path.join(dir, '.eslintrc.json')); | ||
| const plugins = Object.fromEntries(await Promise.all((config.plugins || []) | ||
| .map((p: string) => transform(p, 'eslint-plugin')) | ||
| .map((p: string) => import(p).then(({ default: d }) => [p, d])))); | ||
|
|
||
| const eslint = new ESLint({ | ||
| cwd: dir, | ||
| // todo: fix | ||
| fix: false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Detect cmd arg and set this to true or false here |
||
| plugins, | ||
| baseConfig: {}, | ||
| // we use glob on passed in files, due to https://github.com/eslint/eslint/issues/5623 | ||
simlu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ignore: false, | ||
| reportUnusedDisableDirectives: 'error' | ||
| }); | ||
| const results = await eslint.lintFiles(files); | ||
| await ESLint.outputFixes(results); | ||
| const formatter = await eslint.loadFormatter('stylish'); | ||
| const resultText = formatter.format(results); | ||
|
|
||
| expect(resultText).to.equal(''); | ||
|
|
||
| const result = results.every( | ||
| (e: { warningCount: number, errorCount: number }) => e.warningCount === 0 && e.errorCount === 0 | ||
| ); | ||
| expect(result, 'Linter Problem').to.equal(true); | ||
| expect(fs.smartWrite(path.join(dir, '.eslint/linted.txt'), files)).to.equal(false); | ||
simlu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.