Skip to content
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

refactor: better typescript support and linting #291

Merged
merged 22 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
key: v1-dependencies-{{ checksum "package.json" }}

- run: yarn lint

- run: yarn build-scripts

- run: yarn build

Expand Down
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
.eslintrc.js
packages/test
packages/test
packages/@averjs/vue-app/templates
scripts-build
121 changes: 85 additions & 36 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,102 @@
const averConfig = require('@averjs/eslint-config');

// @ts-check
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
plugins: ['unicorn', 'import'],
env: {
jest: true
},
extends: [
'standard',
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings'
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts']
},
'import/resolver': {
node: {
extensions: ['.js', '.json', '.ts', '.d.ts']
},
typescript: {
project: require('path').resolve(__dirname, './tsconfig.eslint.json')
}
}
},
rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'none'
}
],

'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
'unicorn/expiring-todo-comments': 'error',
'unicorn/no-array-instanceof': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-text-content': 'error',
'unicorn/throw-new-error': 'error'
},
overrides: [
{
files: [
'**/*.ts'
],
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'unicorn'
],
env: {
jest: true
parserOptions: {
sourceType: 'module',
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json']
},
plugins: ['@typescript-eslint'],
extends: [
'standard',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
'plugin:prettier/recommended',
'prettier/@typescript-eslint'
],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',

'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],

'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],

...averConfig.rules,
...{ 'unicorn/no-process-exit': 'off' }
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',

'@typescript-eslint/no-floating-promises': [
'error',
{ ignoreIIFE: true }
]
}
},
{
files: [
'**/*.js',
'**/*.vue'
],
extends: [
'@averjs'
]
},
{
files: [
'packages/@averjs/vue-app/templates/**/*.js'
],
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2015
},
extends: [
'plugin:lodash-template/recommended-with-script',
]
files: ['**/*.js', '**/*.vue'],
extends: ['@averjs', 'plugin:prettier/recommended'],
rules: {
'space-before-function-paren': 'off'
}
}
// {
// files: ['packages/@averjs/vue-app/templates/**/*.js'],
// parserOptions: {
// parser: 'babel-eslint',
// ecmaVersion: 2015
// },
// extends: ['plugin:lodash-template/recommended-with-script']
// }
]
};
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ yarn-error.log
tmp
verdaccio
packages/test
.changelog
.changelog
temp
scripts-build
49 changes: 49 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"apiReport": {
"enabled": true,
"reportFolder": "<projectFolder>/temp/"
},

"docModel": {
"enabled": true
},

"dtsRollup": {
"enabled": true
},

"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},

"ae-missing-release-tag": {
"logLevel": "none"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
},

"tsdoc-undefined-tag": {
"logLevel": "none"
}
}
}
}
15 changes: 5 additions & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
clearMocks: true,

coverageDirectory: './coverage/',
collectCoverage: true,
coveragePathIgnorePatterns: [
'__fixtures__'
],
coveragePathIgnorePatterns: ['__fixtures__'],

testEnvironment: 'node',
moduleFileExtensions: [
'js', 'json', 'ts'
],
moduleFileExtensions: ['js', 'json', 'ts'],
transform: {
'^.+\\.js?$': 'babel-jest',
'^.+\\.ts?$': 'ts-jest'
},
testMatch: [
'**/__tests__/**/*.spec.js',
'**/__tests__/**/*.spec.ts'
]
testMatch: ['**/__tests__/**/*.spec.js', '**/__tests__/**/*.spec.ts']
};
51 changes: 19 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,47 @@
"packages/test"
],
"scripts": {
"build-scripts": "rm -Rf scripts-build && tsc --project tsconfig.scripts.json && mv scripts/dist/scripts scripts-build && rm -Rf scripts/dist",
"rm-dist": "find ./packages/@averjs -name 'dist' -maxdepth 2 -exec rm -Rf {} \\;",
"dev": "node -r esm ./scripts/dev --watch",
"build": "node -r esm ./scripts/dev",
"release": "node -r esm ./scripts/release",
"lint": "eslint --ext .ts,.js,.vue .",
"dev": "node ./scripts-build/dev --watch",
"build": "yarn rm-dist && node ./scripts-build/dev",
"release": "node ./scripts-build/release-script",
"lint": "eslint --ext .js,.ts,.vue .",
"test": "jest && codecov",
"version": "node -r esm ./scripts/generateChangelog.js && git add CHANGELOG.md"
"version": "node ./scripts-build/generateChangelog.ts && git add CHANGELOG.md"
},
"devDependencies": {
"@microsoft/api-extractor": "7.11.4",
"@rollup/plugin-json": "4.1.0",
"@types/command-line-usage": "5.0.1",
"@types/compression": "1.7.0",
"@types/cookie-parser": "1.4.2",
"@types/copy-webpack-plugin": "6.0.0",
"@types/cross-spawn": "6.0.2",
"@types/csurf": "1.9.36",
"@types/helmet": "0.0.48",
"@types/html-minifier": "4.0.0",
"@types/klaw-sync": "6.0.0",
"@types/lodash": "4.14.163",
"@types/lru-cache": "5.1.0",
"@types/memory-fs": "0.3.2",
"@types/minimist": "1.2.0",
"@types/morgan": "1.9.2",
"@types/optimize-css-assets-webpack-plugin": "5.0.1",
"@types/postcss-preset-env": "6.7.0",
"@types/postcss-safe-parser": "4.0.0",
"@types/serialize-javascript": "5.0.0",
"@types/terser-webpack-plugin": "4.2.0",
"@types/uuid": "8.3.0",
"@types/webpack": "4.41.24",
"@types/webpack-node-externals": "2.5.0",
"@types/webpackbar": "4.0.0",
"@types/workbox-webpack-plugin": "5.1.5",
"@types/conventional-recommended-bump": "6.0.0",
"@types/inquirer": "7.3.1",
"@types/pify": "3.0.2",
"@types/semver": "7.3.4",
"@typescript-eslint/eslint-plugin": "4.6.0",
"@typescript-eslint/parser": "4.6.0",
"codecov": "3.8.0",
"cross-spawn": "7.0.3",
"eslint": "7.12.1",
"eslint-config-prettier": "6.15.0",
"eslint-config-standard": "16.0.1",
"eslint-import-resolver-typescript": "2.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.1.0",
"eslint-plugin-lodash-template": "^0.19.0",
"eslint-plugin-lodash-template": "0.19.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.2",
"eslint-plugin-vue": "7.1.0",
"esm": "3.2.25",
"execa": "4.1.0",
"inquirer": "7.3.3",
"jest": "26.6.1",
"lerna": "3.22.1",
"lerna-changelog": "1.0.1",
"memfs": "3.2.0",
"ora": "5.1.0",
"package-json": "^6.5.0",
"pify": "5.0.0",
"rollup": "2.32.1",
"rollup-plugin-babel": "4.4.0",
Expand All @@ -70,8 +57,8 @@
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.28.0",
"ts-jest": "26.4.3",
"ts-node": "9.0.0",
"typescript": "4.0.5",
"verdaccio": "4.8.1"
},
"dependencies": {}
}
}
38 changes: 22 additions & 16 deletions packages/@averjs/babel-preset-app/__tests__/getPolyfills.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ test('getDefaultPolyfills should return the correct polyfills by core-js version
});

test('getPolyfills should return the correct polyfills by core-js version', () => {
let polyfills = getPolyfills(2, {
browsers: [
'IE >= 9'
]
}, getDefaultPolyfills(2), {
ignoreBrowserslistConfig: false,
configPath: ''
});
let polyfills = getPolyfills(
2,
{
browsers: ['IE >= 9']
},
getDefaultPolyfills(2),
{
ignoreBrowserslistConfig: false,
configPath: ''
}
);

expect(polyfills).toEqual([
'es6.array.iterator',
Expand All @@ -37,14 +40,17 @@ test('getPolyfills should return the correct polyfills by core-js version', () =
'es7.promise.finally'
]);

polyfills = getPolyfills(3, {
browsers: [
'IE >= 9'
]
}, getDefaultPolyfills(3), {
ignoreBrowserslistConfig: false,
configPath: ''
});
polyfills = getPolyfills(
3,
{
browsers: ['IE >= 9']
},
getDefaultPolyfills(3),
{
ignoreBrowserslistConfig: false,
configPath: ''
}
);

expect(polyfills).toEqual([
'es.array.iterator',
Expand Down
Loading