Skip to content

Commit 5160ae2

Browse files
committed
chore: Upgrade to TypeScript 4
BREAKING CHANGE: Upgrade to TypeScript 4
1 parent 9474cc7 commit 5160ae2

File tree

10 files changed

+165
-115
lines changed

10 files changed

+165
-115
lines changed

.eslintrc.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
module.exports = {
2-
'root': true,
3-
'env': {
4-
'es6': true,
5-
'node': true
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
browser: true,
67
},
7-
'extends': [
8-
'eslint:recommended',
9-
'plugin:unicorn/recommended',
10-
],
11-
'parser': '@typescript-eslint/parser',
12-
'parserOptions': {
13-
'ecmaVersion': 2017,
14-
'sourceType': 'module'
8+
extends: ['eslint:recommended', 'plugin:unicorn/recommended'],
9+
parser: '@typescript-eslint/parser',
10+
parserOptions: {
11+
project: 'tsconfig.json',
12+
sourceType: 'module',
13+
ecmaFeatures: {
14+
jsx: false,
15+
},
16+
warnOnUnsupportedTypeScriptVersion: false,
1517
},
16-
'plugins': [
17-
'unicorn',
18-
'typescript',
19-
'import',
20-
],
21-
'rules': {
22-
'no-undef': 0,
18+
plugins: ['unicorn'],
19+
rules: {
20+
// core
2321
'no-unused-vars': 0,
24-
'indent': 0,
25-
'unicorn/import-index': 0,
26-
'import/newline-after-import': 0,
27-
'import/no-duplicates': 1,
28-
'import/max-dependencies': [1, { 'max': 10 }],
29-
'quotes': [1, 'single', { 'allowTemplateLiterals': true }],
30-
'semi': [1, 'always'],
31-
}
22+
'consistent-return': [1, { treatUndefinedAsUnspecified: true }],
23+
quotes: [1, 'single', { allowTemplateLiterals: true, avoidEscape: true }],
24+
semi: [1, 'always'],
25+
'max-lines': [1, { max: 200 }],
26+
'max-params': [1, { max: 5 }],
27+
'no-unneeded-ternary': [1],
28+
// unicorn
29+
'unicorn/prefer-spread': 0,
30+
'unicorn/catch-error-name': 0,
31+
'unicorn/prevent-abbreviations': [
32+
1,
33+
{
34+
replacements: {
35+
args: false,
36+
err: false,
37+
prod: false,
38+
ref: false,
39+
params: false,
40+
},
41+
},
42+
],
43+
},
3244
};

.prettierrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
printWidth: 100,
3+
trailingComma: 'all',
4+
tabWidth: 4,
5+
semi: true,
6+
singleQuote: true,
7+
overrides: [
8+
{
9+
files: '*.{json,yml}',
10+
options: {
11+
tabWidth: 2,
12+
},
13+
},
14+
],
15+
};

.releaserc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
plugins: [
3+
'@semantic-release/commit-analyzer',
4+
'@semantic-release/release-notes-generator',
5+
'@semantic-release/changelog',
6+
[
7+
'@semantic-release/npm',
8+
{
9+
pkgRoot: 'dist',
10+
},
11+
],
12+
'@semantic-release/github',
13+
'@semantic-release/git',
14+
],
15+
};

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018
3+
Copyright (c) 2020
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Taskfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
PATH="$PWD/node_modules/.bin":$PATH
3+
set -e
4+
5+
build() {
6+
set -x
7+
rm -rfv dist
8+
cp -rfv src dist
9+
cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' > dist/tsconfig.json
10+
cp -fv README.md LICENSE package.json dist
11+
cd dist
12+
/usr/bin/find . -name '*.spec.ts' | xargs rm -rvf
13+
tsc -p .
14+
rm -rvf tsconfig.json
15+
/usr/bin/find . -name '*.ts' | xargs rm -rvf
16+
cd ..
17+
set +x
18+
}
19+
20+
"$@"

package.json

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22
"name": "eslint-plugin-tsc",
33
"version": "1.2.0",
44
"license": "MIT",
5-
"description": "eslint-plugin-tsc",
6-
"main": "dist/index.js",
7-
"typings": "src/index.ts",
5+
"description": "Wraps a TypeScript compiler checks",
6+
"main": "index.js",
7+
"keywords": [
8+
"eslint",
9+
"eslint-plugin",
10+
"eslintplugin",
11+
"eslint-rules",
12+
"typescript",
13+
"typescript-service"
14+
],
815
"scripts": {
916
"test": "npm run eslint && npm run tscheck && npm run test:r",
10-
"test:r": "npm run mocha -- src/*.spec.ts",
11-
"mocha": "node -r ts-node/register/transpile-only node_modules/mocha/bin/_mocha --timeout 5000",
12-
"test:w": "npm run mocha -- --watch-extensions ts --watch src/**/*.spec.ts",
13-
"test:d": "node --inspect-brk -r ts-node/register/transpile-only node_modules/mocha/bin/_mocha --no-timeouts src/**/*.spec.ts",
17+
"test:r": "mocha -r ts-node/register/transpile-only --no-timeouts src/**/*.spec.ts",
18+
"test:w": "mocha -r ts-node/register/transpile-only --watch-files src/**/*.ts --watch src/**/*.spec.ts",
19+
"test:d": "node --inspect-brk -r ts-node/register/transpile-only node_modules/mocha/bin/_mocha --no-timeouts --watch-files src/**/*.ts --watch src/**/*.spec.ts",
1420
"tscheck": "echo tscheck... && tsc --noEmit",
1521
"tscheck:w": "npm run tscheck -- --watch",
1622
"tsclint": "tsc --noEmit --pretty false --strictNullChecks --forceConsistentCasingInFileNames --noImplicitReturns --noImplicitThis --noUnusedLocals --noUnusedParameters",
1723
"tsclint:w": "npm run tsclint -- --watch",
18-
"eslint": "eslint src --ext ts",
19-
"eslint:fix": "eslint src --ext \"ts\" --fix",
20-
"eslint:w": "chokidar \"src/**/*.ts\" --initial -c \"npm run eslint\"",
21-
"semantic-release": "semantic-release",
22-
"prepublishOnly": "npm run build && sed -i -e 's/devDependencies/_devDependencies/g' package.json",
23-
"build": "tsc",
24-
"prebuild": "npm run clean",
25-
"clean": "rimraf dist",
26-
"commit": "git-cz"
24+
"eslint": "node node_modules/eslint/bin/eslint \"src/**/*.{ts,tsx}\"",
25+
"eslint:w": "watchexec -w src \"npm run eslint\"",
26+
"eslint:fix": "npm run eslint -- --fix",
27+
"build": "sh Taskfile build",
28+
"prettier:format": "npx prettier src --write"
2729
},
2830
"dependencies": {
2931
"typescript-service": "^2.0.3"
@@ -34,62 +36,28 @@
3436
"@semantic-release/npm": "^7.0.6",
3537
"@types/eslint": "^7.2.2",
3638
"@types/mocha": "^8.0.3",
37-
"@types/node": "^14.10.1",
38-
"chokidar-cli": "^2.1.0",
39-
"conventional-changelog-eslint": "^3.0.8",
40-
"cz-adapter-eslint": "^0.3.0",
39+
"@types/node": "^14.10.2",
40+
"@typescript-eslint/parser": "^4.1.1",
4141
"eslint": "^7.9.0",
42-
"eslint-plugin-import": "^2.22.0",
43-
"eslint-plugin-typescript": "^0.14.0",
4442
"eslint-plugin-unicorn": "^21.0.0",
4543
"mocha": "^8.1.3",
46-
"rimraf": "^3.0.2",
44+
"prettier": "^2.1.1",
4745
"semantic-release": "^17.1.1",
4846
"ts-node": "^9.0.0",
49-
"typescript": "4.0.2",
50-
"@typescript-eslint/parser": "^4.1.1"
47+
"typescript": "^4.0.2",
48+
"typescript-service": "^2.0.3",
49+
"watchexec-bin": "^1.0.0"
5150
},
5251
"engines": {
5352
"node": ">=12",
5453
"npm": ">=6"
5554
},
5655
"repository": {
5756
"type": "git",
58-
"url": "https://github.com/unlight/eslint-plugin-tsc.git"
57+
"url": "git+https://github.com/unlight/eslint-plugin-tsc.git"
5958
},
60-
"keywords": [],
61-
"release": {
62-
"generateNotes": {
63-
"preset": "eslint"
64-
},
65-
"analyzeCommits": {
66-
"preset": "eslint"
67-
},
68-
"verifyConditions": [
69-
"@semantic-release/changelog",
70-
"@semantic-release/github",
71-
"@semantic-release/npm",
72-
"@semantic-release/git"
73-
],
74-
"prepare": [
75-
"@semantic-release/changelog",
76-
"@semantic-release/npm",
77-
"@semantic-release/git"
78-
],
79-
"publish": [
80-
"@semantic-release/npm",
81-
"@semantic-release/github"
82-
],
83-
"success": [
84-
"@semantic-release/github"
85-
],
86-
"fail": [
87-
"@semantic-release/github"
88-
]
59+
"bugs": {
60+
"url": "https://github.com/unlight/eslint-plugin-tsc/issues"
8961
},
90-
"config": {
91-
"commitizen": {
92-
"path": "./node_modules/cz-adapter-eslint"
93-
}
94-
}
62+
"homepage": "https://github.com/unlight/eslint-plugin-tsc#readme"
9563
}

src/config.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { rules } from './index';
1+
import { rules } from '.';
22
import { RuleTester } from 'eslint';
33
import { resolve } from 'path';
44

55
const ruleTester = new RuleTester({
66
parser: require.resolve('@typescript-eslint/parser'),
77
parserOptions: {
8-
ecmaVersion: 2017,
8+
ecmaVersion: 2019,
99
sourceType: 'module',
1010
ecmaFeatures: {},
1111
},
@@ -20,16 +20,24 @@ ruleTester.run('tests', rules.config as any, {
2020
code: 'test-project/errors.ts',
2121
options: [{ configFile: 'test-project/tsconfig.json' }],
2222
errors: [
23-
{ message: 'Type \'number\' is not assignable to type \'string\'.', line: 2, column: 7 },
24-
{ message: 'Type \'string\' is not assignable to type \'number\'.', line: 3, column: 7 },
25-
]
23+
{
24+
message: "Type 'number' is not assignable to type 'string'.",
25+
line: 2,
26+
column: 7,
27+
},
28+
{
29+
message: "Type 'string' is not assignable to type 'number'.",
30+
line: 3,
31+
column: 7,
32+
},
33+
],
2634
},
2735
],
2836
valid: [
2937
{
3038
filename: resolve('test-project/source.ts'),
3139
code: 'test-project/source.ts',
3240
options: [{ configFile: `${root}/test-project/tsconfig.json` }],
33-
}
41+
},
3442
],
3543
});

src/config.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { createService } from 'typescript-service';
55
let service: ReturnType<typeof createService>;
66

77
export function create(context: Rule.RuleContext) {
8-
9-
const { compilerOptions, configFile } = context.options[0] || { compilerOptions: {}, configFile: undefined };
8+
const { compilerOptions, configFile } = context.options[0] || {
9+
compilerOptions: {},
10+
configFile: undefined,
11+
};
1012
if (!service) {
1113
service = createService({ compilerOptions, configFile });
1214
}
@@ -15,14 +17,16 @@ export function create(context: Rule.RuleContext) {
1517
const soureText = context.getSourceCode().text;
1618

1719
const diagnostics = service.getDiagnostics(fileName, soureText);
18-
diagnostics.forEach(diagnostic => {
19-
if (diagnostic.file) {
20-
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
20+
diagnostics.forEach((diagnostic) => {
21+
if (diagnostic.file && diagnostic.start !== undefined) {
22+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(
23+
diagnostic.start,
24+
);
2125
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
2226
context.report({
2327
message,
2428
loc: { line: line + 1, column: character },
25-
messageId: undefined
29+
messageId: undefined,
2630
});
2731
}
2832
});
@@ -44,7 +48,7 @@ export const config = {
4448
required: ['configFile'],
4549
properties: {
4650
configFile: {
47-
type: 'string'
51+
type: 'string',
4852
},
4953
compilerOptions: {
5054
type: 'object',

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { config } from './config';
22
import { Rule } from 'eslint';
33

4-
type RuleDict = { [id: string]: Rule.RuleModule | ((context: Rule.RuleContext) => Rule.RuleListener) };
4+
type RuleDict = {
5+
[id: string]: Rule.RuleModule | ((context: Rule.RuleContext) => Rule.RuleListener);
6+
};
57

68
export const rules: RuleDict = {
79
config,

tsconfig.json

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
{
2+
"ts-node": {
3+
"transpileOnly": true,
4+
"compilerOptions": {
5+
"module": "commonjs"
6+
}
7+
},
28
"compilerOptions": {
3-
"target": "es2015",
9+
"target": "es2017",
410
"module": "commonjs",
511
"moduleResolution": "node",
612
"importHelpers": true,
7-
"declaration": false,
13+
"strict": true,
14+
"noImplicitAny": false,
15+
"experimentalDecorators": false,
16+
"emitDecoratorMetadata": false,
817
"outDir": "dist",
9-
"pretty": false,
18+
"pretty": true,
19+
"esModuleInterop": true,
1020
"removeComments": false,
11-
"sourceMap": true,
12-
"lib": [
13-
"esnext"
14-
]
21+
"sourceMap": false,
22+
"declaration": false,
23+
"declarationMap": false,
24+
"skipLibCheck": true,
25+
"lib": ["esnext"]
1526
},
16-
"include": [
17-
"src/**/*.ts"
18-
],
19-
"exclude": [
20-
"src/**/*.spec.ts"
21-
]
27+
"include": ["src/**/*.ts"]
2228
}

0 commit comments

Comments
 (0)