Skip to content

Commit c5087ff

Browse files
authored
Merge pull request #6 from ibc/master
Modernize to TypeScript
2 parents d34fcd6 + 456ff77 commit c5087ff

22 files changed

+6104
-339
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# NOTE: This file and .prettierignore must contain same paths.
2+
3+
/.cache
4+
/coverage
5+
/doc
6+
/lib

.eslintrc.js

Lines changed: 102 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,51 @@
1-
module.exports =
2-
{
3-
env:
4-
{
5-
browser: false,
1+
const eslintConfig = {
2+
env: {
63
es6: true,
7-
node: true
4+
node: true,
85
},
9-
extends:
10-
[
11-
'eslint:recommended'
12-
],
6+
plugins: ['prettier'],
137
settings: {},
14-
parserOptions:
15-
{
16-
ecmaVersion: 2018,
8+
parserOptions: {
9+
ecmaVersion: 2022,
1710
sourceType: 'module',
18-
ecmaFeatures:
19-
{
20-
impliedStrict: true
21-
}
11+
ecmaFeatures: {
12+
impliedStrict: true,
13+
},
14+
lib: ['es2022'],
2215
},
23-
rules:
24-
{
25-
'array-bracket-spacing': [ 2, 'always',
26-
{
27-
objectsInArrays: true,
28-
arraysInArrays: true
29-
}],
30-
'arrow-parens': [ 2, 'always' ],
31-
'arrow-spacing': 2,
32-
'block-spacing': [ 2, 'always' ],
33-
'brace-style': [ 2, 'allman', { allowSingleLine: true } ],
34-
'camelcase': 2,
35-
'comma-dangle': 2,
36-
'comma-spacing': [ 2, { before: false, after: true } ],
37-
'comma-style': 2,
38-
'computed-property-spacing': 2,
16+
globals: {
17+
NodeJS: 'readonly',
18+
},
19+
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
20+
rules: {
21+
'prettier/prettier': 2,
3922
'constructor-super': 2,
40-
'func-call-spacing': 2,
41-
'generator-star-spacing': 2,
42-
'guard-for-in': 2,
43-
'indent': [ 2, 'tab', { 'SwitchCase': 1 } ],
44-
'key-spacing': [ 2,
45-
{
46-
singleLine:
23+
curly: [2, 'all'],
24+
// Unfortunatelly `curly` does not apply to blocks in `switch` cases so
25+
// this is needed.
26+
'no-restricted-syntax': [
27+
2,
4728
{
48-
beforeColon: false,
49-
afterColon: true
29+
selector: 'SwitchCase > *.consequent[type!="BlockStatement"]',
30+
message: 'Switch cases without blocks are disallowed',
5031
},
51-
multiLine:
52-
{
53-
beforeColon: true,
54-
afterColon: true,
55-
align: 'colon'
56-
}
57-
}],
58-
'keyword-spacing': 2,
59-
'linebreak-style': [ 2, 'unix' ],
60-
'lines-around-comment': [ 2,
61-
{
62-
allowBlockStart: true,
63-
allowObjectStart: true,
64-
beforeBlockComment: true,
65-
beforeLineComment: false
66-
}],
67-
'max-len': [ 2, 90,
68-
{
69-
tabWidth: 2,
70-
comments: 100,
71-
ignoreUrls: true,
72-
ignoreStrings: true,
73-
ignoreTemplateLiterals: true,
74-
ignoreRegExpLiterals: true
75-
}],
32+
],
33+
'guard-for-in': 2,
7634
'newline-after-var': 2,
7735
'newline-before-return': 2,
78-
'newline-per-chained-call': 2,
7936
'no-alert': 2,
8037
'no-caller': 2,
8138
'no-case-declarations': 2,
8239
'no-catch-shadow': 2,
8340
'no-class-assign': 2,
84-
'no-confusing-arrow': 2,
8541
'no-console': 2,
8642
'no-const-assign': 2,
8743
'no-debugger': 2,
8844
'no-dupe-args': 2,
8945
'no-dupe-keys': 2,
9046
'no-duplicate-case': 2,
9147
'no-div-regex': 2,
92-
'no-empty': [ 2, { allowEmptyCatch: true } ],
48+
'no-empty': [2, { allowEmptyCatch: true }],
9349
'no-empty-pattern': 2,
9450
'no-else-return': 0,
9551
'no-eval': 2,
@@ -98,7 +54,6 @@ module.exports =
9854
'no-extra-bind': 2,
9955
'no-extra-boolean-cast': 2,
10056
'no-extra-label': 2,
101-
'no-extra-semi': 2,
10257
'no-fallthrough': 2,
10358
'no-func-assign': 2,
10459
'no-global-assign': 2,
@@ -109,11 +64,7 @@ module.exports =
10964
'no-invalid-this': 2,
11065
'no-irregular-whitespace': 2,
11166
'no-lonely-if': 2,
112-
'no-mixed-operators': 2,
113-
'no-mixed-spaces-and-tabs': 2,
114-
'no-multi-spaces': 2,
11567
'no-multi-str': 2,
116-
'no-multiple-empty-lines': [ 1, { max: 1, maxEOF: 0, maxBOF: 0 } ],
11768
'no-native-reassign': 2,
11869
'no-negated-in-lhs': 2,
11970
'no-new': 2,
@@ -131,43 +82,97 @@ module.exports =
13182
'no-sequences': 2,
13283
'no-shadow': 2,
13384
'no-shadow-restricted-names': 2,
134-
'no-spaced-func': 2,
13585
'no-sparse-arrays': 2,
13686
'no-this-before-super': 2,
13787
'no-throw-literal': 2,
13888
'no-undef': 2,
139-
'no-unexpected-multiline': 2,
14089
'no-unmodified-loop-condition': 2,
14190
'no-unreachable': 2,
142-
'no-unused-vars': [ 1, { vars: 'all', args: 'after-used' }],
143-
'no-use-before-define': [ 2, { functions: false } ],
91+
'no-unused-vars': [1, { vars: 'all', args: 'after-used' }],
92+
'no-use-before-define': 0,
14493
'no-useless-call': 2,
14594
'no-useless-computed-key': 2,
14695
'no-useless-concat': 2,
14796
'no-useless-rename': 2,
14897
'no-var': 2,
149-
'no-whitespace-before-property': 2,
15098
'object-curly-newline': 0,
151-
'object-curly-spacing': [ 2, 'always' ],
152-
'object-property-newline': [ 2, { allowMultiplePropertiesPerLine: true } ],
15399
'prefer-const': 2,
154100
'prefer-rest-params': 2,
155101
'prefer-spread': 2,
156102
'prefer-template': 2,
157-
'quotes': [ 2, 'single', { avoidEscape: true } ],
158-
'semi': [ 2, 'always' ],
159-
'semi-spacing': 2,
160-
'space-before-blocks': 2,
161-
'space-before-function-paren': [ 2,
162-
{
163-
anonymous : 'never',
164-
named : 'never',
165-
asyncArrow : 'always'
166-
}],
167-
'space-in-parens': [ 2, 'never' ],
168-
'spaced-comment': [ 2, 'always' ],
169-
'strict': 2,
103+
'spaced-comment': [2, 'always'],
104+
strict: 2,
170105
'valid-typeof': 2,
171-
'yoda': 2
172-
}
106+
yoda: 2,
107+
},
108+
overrides: [],
173109
};
110+
111+
const tsRules = {
112+
'no-unused-vars': 0,
113+
'@typescript-eslint/ban-types': 0,
114+
'@typescript-eslint/ban-ts-comment': 0,
115+
'@typescript-eslint/ban-ts-ignore': 0,
116+
'@typescript-eslint/explicit-module-boundary-types': 0,
117+
'@typescript-eslint/semi': 2,
118+
'@typescript-eslint/member-delimiter-style': [
119+
2,
120+
{
121+
multiline: { delimiter: 'semi', requireLast: true },
122+
singleline: { delimiter: 'semi', requireLast: false },
123+
},
124+
],
125+
'@typescript-eslint/no-explicit-any': 0,
126+
'@typescript-eslint/no-unused-vars': [
127+
2,
128+
{
129+
vars: 'all',
130+
args: 'after-used',
131+
ignoreRestSiblings: false,
132+
},
133+
],
134+
'@typescript-eslint/no-use-before-define': [2, { functions: false }],
135+
'@typescript-eslint/no-empty-function': 0,
136+
'@typescript-eslint/no-non-null-assertion': 0,
137+
};
138+
139+
eslintConfig.overrides.push({
140+
files: ['*.ts'],
141+
parser: '@typescript-eslint/parser',
142+
parserOptions: {
143+
...eslintConfig.parserOptions,
144+
project: 'tsconfig.json',
145+
},
146+
plugins: [...eslintConfig.plugins, '@typescript-eslint'],
147+
extends: [
148+
'plugin:@typescript-eslint/eslint-recommended',
149+
'plugin:@typescript-eslint/recommended',
150+
...eslintConfig.extends,
151+
],
152+
rules: { ...eslintConfig.rules, ...tsRules },
153+
});
154+
155+
eslintConfig.overrides.push({
156+
files: ['src/test/*.ts'],
157+
parserOptions: {
158+
...eslintConfig.parserOptions,
159+
project: 'tsconfig.json',
160+
},
161+
env: {
162+
...eslintConfig.env,
163+
'jest/globals': true,
164+
},
165+
extends: [
166+
'plugin:@typescript-eslint/eslint-recommended',
167+
'plugin:@typescript-eslint/recommended',
168+
...eslintConfig.extends,
169+
],
170+
plugins: [...eslintConfig.plugins, '@typescript-eslint', 'jest'],
171+
rules: {
172+
...eslintConfig.rules,
173+
...tsRules,
174+
'jest/no-disabled-tests': 2,
175+
},
176+
});
177+
178+
module.exports = eslintConfig;

.github/workflows/pick-port.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: pick-port
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
concurrency:
6+
# Cancel a currently running workflow from the same PR, branch or tag when a
7+
# new workflow is triggered.
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
ci:
13+
strategy:
14+
matrix:
15+
ci:
16+
- os: ubuntu-20.04
17+
node: 16
18+
- os: ubuntu-20.04
19+
node: 18
20+
- os: ubuntu-22.04
21+
node: 20
22+
- os: macos-12
23+
node: 20
24+
- os: windows-2022
25+
node: 20
26+
27+
runs-on: ${{ matrix.ci.os }}
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: ${{ matrix.ci.node }}
37+
38+
- name: Configure cache
39+
uses: actions/cache@v3
40+
with:
41+
path: |
42+
~/.npm
43+
key: ${{ matrix.ci.os }}-node-${{ hashFiles('**/package.json') }}
44+
restore-keys: |
45+
${{ matrix.ci.os }}-node-
46+
47+
- name: npm ci
48+
run: npm ci --foreground-scripts
49+
50+
- name: npm run lint
51+
run: npm run lint
52+
53+
- name: npm run test
54+
run: npm run test
55+
env:
56+
DEBUG: 'pick-port:tests*'

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
/node_modules/
2-
/npm-debug.log
1+
## Node.
2+
/node_modules
3+
/lib
4+
5+
## Others.
6+
/.cache
7+
/coverage

.npmrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
package-lock=false
1+
# Generate package-lock.json.
2+
package-lock=true
3+
# For bad node/npm version to throw actual error.
4+
engine-strict=true

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# NOTE: This file and .eslintignore must contain same paths.
2+
3+
/.cache
4+
/coverage
5+
/doc
6+
/lib

.prettierrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"useTabs": true,
3+
"tabWidth": 2,
4+
"arrowParens": "avoid",
5+
"bracketSpacing": true,
6+
"semi": true,
7+
"singleQuote": true,
8+
"trailingComma": "all",
9+
"endOfLine": "auto"
10+
}

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright © 2018, José Luis Millán <[email protected]>
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

0 commit comments

Comments
 (0)