-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite to TypeScript … (#202)
BREAKING CHANGE: Drop Flow, bump minimum Node version to 12. Co-authored-by: Matthew Fernando Garcia <[email protected]>
- Loading branch information
1 parent
f3b0c37
commit 459f335
Showing
49 changed files
with
1,545 additions
and
2,343 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
module.exports = { | ||
plugins: [ | ||
'@babel/proposal-nullish-coalescing-operator', | ||
'@babel/proposal-optional-chaining', | ||
], | ||
plugins: ['@babel/proposal-nullish-coalescing-operator'], | ||
presets: [ | ||
[ | ||
'@babel/env', | ||
{ | ||
modules: process.env.NODE_ENV === 'test' && 'commonjs', | ||
targets: {node: '6'}, | ||
targets: {node: '12'}, | ||
}, | ||
], | ||
'@babel/flow', | ||
'@babel/typescript', | ||
], | ||
}; |
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
File renamed without changes.
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,4 +1,3 @@ | ||
coverage/* | ||
dist/* | ||
flow-typed/* | ||
node_modules/* |
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,57 @@ | ||
const rushstackEslintConfig = require('@rushstack/eslint-config/profile/node'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const {isDeepStrictEqual} = require('util'); | ||
|
||
// Rushstack: "This is a workaround for https://github.com/eslint/eslint/issues/3458". | ||
require('@rushstack/eslint-config/patch/modern-module-resolution'); | ||
|
||
// ESLint configuration is not user-friendly. | ||
const overrides = rushstackEslintConfig.overrides.filter((override) => | ||
isDeepStrictEqual(override.files, ['*.ts', '*.tsx']), | ||
); | ||
assert( | ||
overrides.length === 1, | ||
"The assumption for locating the .ts override in '@rushstack/eslint-config' is faulty.", | ||
); | ||
|
||
module.exports = { | ||
extends: [ | ||
'@rushstack/eslint-config/profile/node', | ||
'@rushstack/eslint-config/mixins/tsdoc', | ||
'plugin:eslint-comments/recommended', | ||
'plugin:unicorn/recommended', | ||
], | ||
overrides: [ | ||
{ | ||
files: ['types/*.d.ts'], | ||
rules: { | ||
// Type files should have the name of the packages that use them, which don't necessarily follow this rule (e.g. `JSONStream`). | ||
'unicorn/filename-case': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['*.ts'], | ||
rules: { | ||
'@rushstack/typedef-var': 'off', | ||
// Rationale: https://github.com/microsoft/rushstack/blob/63777148e110b2d9b690e60d74e58af03d0e7b7e/stack/eslint-config/index.js#L327-L332 | ||
'@typescript-eslint/naming-convention': overrides[0].rules[ | ||
'@typescript-eslint/naming-convention' | ||
].map((value) => | ||
typeof value === 'object' && value.selector === 'interface' | ||
? {format: ['PascalCase'], selector: 'interface'} | ||
: value, | ||
), | ||
}, | ||
}, | ||
], | ||
parserOptions: { | ||
project: path.join(__dirname, './tsconfig.json'), | ||
}, | ||
rules: { | ||
'eslint-comments/no-unused-disable': 'error', | ||
// Since this is covered by 'eslint-comments/no-unlimited-disable'. | ||
'unicorn/no-abusive-eslint-disable': 'off', | ||
'unicorn/no-unsafe-regex': 'error', | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 +1,5 @@ | ||
coverage | ||
dist | ||
lib | ||
node_modules | ||
yarn.lock | ||
yarn-debug.log* | ||
yarn-error.log* | ||
*.log* |
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,3 @@ | ||
hooks: | ||
commit-msg: commitlint -e $HUSKY_GIT_PARAMS | ||
pre-commit: tsc && cross-env NODE_ENV=test lint-staged |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
'*.{json,md,yaml}': | ||
- 'prettier --write' | ||
'*.{js,ts}': | ||
- 'prettier --write' | ||
- 'eslint --fix' | ||
- 'jest --config ./scripts/jest/config.source.js --bail --findRelatedTests' |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,41 +1,42 @@ | ||
// @flow | ||
import mapToMap from 'map-to-map'; | ||
|
||
let files: Map<string, Buffer> = new Map(); | ||
|
||
function __setFiles(newFiles: {[path: string]: Buffer}) { | ||
function _setFiles(newFiles: {[path: string]: Buffer}): void { | ||
files = mapToMap(newFiles); | ||
} | ||
|
||
// $FlowFixMe | ||
const readFile = jest.fn( | ||
( | ||
path: string, | ||
encoding: buffer$Encoding, | ||
callback: (error: ?Error, value: ?string) => void, | ||
encoding: BufferEncoding, | ||
// eslint-disable-next-line @rushstack/no-new-null | ||
callback: (error: Error | null, value?: string) => void, | ||
) => { | ||
const file = files.get(path); | ||
if (file && Buffer.isBuffer(file)) { | ||
const decodedFile = file.toString(encoding); | ||
// eslint-disable-next-line unicorn/no-null | ||
callback(null, decodedFile); | ||
} else { | ||
const error = new Error(); | ||
callback(error, null); | ||
const error = new Error('File not found.'); | ||
callback(error); | ||
} | ||
}, | ||
); | ||
|
||
// $FlowFixMe | ||
const readFileSync = jest.fn((path: string, encoding: buffer$Encoding) => { | ||
const readFileSync = jest.fn((path: string, encoding: BufferEncoding) => { | ||
const file = files.get(path); | ||
if (file && Buffer.isBuffer(file)) { | ||
return file.toString(encoding); | ||
} | ||
throw new Error(); | ||
throw new Error('File not found.'); | ||
}); | ||
|
||
module.exports = { | ||
__setFiles, | ||
_setFiles, | ||
readFile, | ||
readFileSync, | ||
}; |
Oops, something went wrong.