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

Modernize to TypeScript #6

Merged
merged 11 commits into from
Jan 9, 2024
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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE: This file and .prettierignore must contain same paths.

/.cache
/coverage
/doc
/lib
199 changes: 102 additions & 97 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,51 @@
module.exports =
{
env:
{
browser: false,
const eslintConfig = {
env: {
es6: true,
node: true
node: true,
},
extends:
[
'eslint:recommended'
],
plugins: ['prettier'],
settings: {},
parserOptions:
{
ecmaVersion: 2018,
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
ecmaFeatures:
{
impliedStrict: true
}
ecmaFeatures: {
impliedStrict: true,
},
lib: ['es2022'],
},
rules:
{
'array-bracket-spacing': [ 2, 'always',
{
objectsInArrays: true,
arraysInArrays: true
}],
'arrow-parens': [ 2, 'always' ],
'arrow-spacing': 2,
'block-spacing': [ 2, 'always' ],
'brace-style': [ 2, 'allman', { allowSingleLine: true } ],
'camelcase': 2,
'comma-dangle': 2,
'comma-spacing': [ 2, { before: false, after: true } ],
'comma-style': 2,
'computed-property-spacing': 2,
globals: {
NodeJS: 'readonly',
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
rules: {
'prettier/prettier': 2,
'constructor-super': 2,
'func-call-spacing': 2,
'generator-star-spacing': 2,
'guard-for-in': 2,
'indent': [ 2, 'tab', { 'SwitchCase': 1 } ],
'key-spacing': [ 2,
{
singleLine:
curly: [2, 'all'],
// Unfortunatelly `curly` does not apply to blocks in `switch` cases so
// this is needed.
'no-restricted-syntax': [
2,
{
beforeColon: false,
afterColon: true
selector: 'SwitchCase > *.consequent[type!="BlockStatement"]',
message: 'Switch cases without blocks are disallowed',
},
multiLine:
{
beforeColon: true,
afterColon: true,
align: 'colon'
}
}],
'keyword-spacing': 2,
'linebreak-style': [ 2, 'unix' ],
'lines-around-comment': [ 2,
{
allowBlockStart: true,
allowObjectStart: true,
beforeBlockComment: true,
beforeLineComment: false
}],
'max-len': [ 2, 90,
{
tabWidth: 2,
comments: 100,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true
}],
],
'guard-for-in': 2,
'newline-after-var': 2,
'newline-before-return': 2,
'newline-per-chained-call': 2,
'no-alert': 2,
'no-caller': 2,
'no-case-declarations': 2,
'no-catch-shadow': 2,
'no-class-assign': 2,
'no-confusing-arrow': 2,
'no-console': 2,
'no-const-assign': 2,
'no-debugger': 2,
'no-dupe-args': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-div-regex': 2,
'no-empty': [ 2, { allowEmptyCatch: true } ],
'no-empty': [2, { allowEmptyCatch: true }],
'no-empty-pattern': 2,
'no-else-return': 0,
'no-eval': 2,
Expand All @@ -98,7 +54,6 @@ module.exports =
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-label': 2,
'no-extra-semi': 2,
'no-fallthrough': 2,
'no-func-assign': 2,
'no-global-assign': 2,
Expand All @@ -109,11 +64,7 @@ module.exports =
'no-invalid-this': 2,
'no-irregular-whitespace': 2,
'no-lonely-if': 2,
'no-mixed-operators': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [ 1, { max: 1, maxEOF: 0, maxBOF: 0 } ],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new': 2,
Expand All @@ -131,43 +82,97 @@ module.exports =
'no-sequences': 2,
'no-shadow': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 2,
'no-undef': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unreachable': 2,
'no-unused-vars': [ 1, { vars: 'all', args: 'after-used' }],
'no-use-before-define': [ 2, { functions: false } ],
'no-unused-vars': [1, { vars: 'all', args: 'after-used' }],
'no-use-before-define': 0,
'no-useless-call': 2,
'no-useless-computed-key': 2,
'no-useless-concat': 2,
'no-useless-rename': 2,
'no-var': 2,
'no-whitespace-before-property': 2,
'object-curly-newline': 0,
'object-curly-spacing': [ 2, 'always' ],
'object-property-newline': [ 2, { allowMultiplePropertiesPerLine: true } ],
'prefer-const': 2,
'prefer-rest-params': 2,
'prefer-spread': 2,
'prefer-template': 2,
'quotes': [ 2, 'single', { avoidEscape: true } ],
'semi': [ 2, 'always' ],
'semi-spacing': 2,
'space-before-blocks': 2,
'space-before-function-paren': [ 2,
{
anonymous : 'never',
named : 'never',
asyncArrow : 'always'
}],
'space-in-parens': [ 2, 'never' ],
'spaced-comment': [ 2, 'always' ],
'strict': 2,
'spaced-comment': [2, 'always'],
strict: 2,
'valid-typeof': 2,
'yoda': 2
}
yoda: 2,
},
overrides: [],
};

const tsRules = {
'no-unused-vars': 0,
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/semi': 2,
'@typescript-eslint/member-delimiter-style': [
2,
{
multiline: { delimiter: 'semi', requireLast: true },
singleline: { delimiter: 'semi', requireLast: false },
},
],
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unused-vars': [
2,
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
},
],
'@typescript-eslint/no-use-before-define': [2, { functions: false }],
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-non-null-assertion': 0,
};

eslintConfig.overrides.push({
files: ['*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
...eslintConfig.parserOptions,
project: 'tsconfig.json',
},
plugins: [...eslintConfig.plugins, '@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
...eslintConfig.extends,
],
rules: { ...eslintConfig.rules, ...tsRules },
});

eslintConfig.overrides.push({
files: ['src/test/*.ts'],
parserOptions: {
...eslintConfig.parserOptions,
project: 'tsconfig.json',
},
env: {
...eslintConfig.env,
'jest/globals': true,
},
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
...eslintConfig.extends,
],
plugins: [...eslintConfig.plugins, '@typescript-eslint', 'jest'],
rules: {
...eslintConfig.rules,
...tsRules,
'jest/no-disabled-tests': 2,
},
});

module.exports = eslintConfig;
56 changes: 56 additions & 0 deletions .github/workflows/pick-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: pick-port

on: [pull_request, workflow_dispatch]

concurrency:
# Cancel a currently running workflow from the same PR, branch or tag when a
# new workflow is triggered.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
ci:
strategy:
matrix:
ci:
- os: ubuntu-20.04
node: 16
- os: ubuntu-20.04
node: 18
- os: ubuntu-22.04
node: 20
- os: macos-12
node: 20
- os: windows-2022
node: 20

runs-on: ${{ matrix.ci.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.ci.node }}

- name: Configure cache
uses: actions/cache@v3
with:
path: |
~/.npm
key: ${{ matrix.ci.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ matrix.ci.os }}-node-

- name: npm ci
run: npm ci --foreground-scripts

- name: npm run lint
run: npm run lint

- name: npm run test
run: npm run test
env:
DEBUG: 'pick-port:tests*'
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/node_modules/
/npm-debug.log
## Node.
/node_modules
/lib

## Others.
/.cache
/coverage
5 changes: 4 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
package-lock=false
# Generate package-lock.json.
package-lock=true
# For bad node/npm version to throw actual error.
engine-strict=true
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE: This file and .eslintignore must contain same paths.

/.cache
/coverage
/doc
/lib
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"useTabs": true,
"tabWidth": 2,
"arrowParens": "avoid",
"bracketSpacing": true,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto"
}
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright © 2018, José Luis Millán <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Loading