diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..a04517ad1 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,27 @@ +module.exports = { + root: true, + env: { + browser: true, + node: true, + es6: true, + }, + parserOptions: { + parser: '@typescript-eslint/parser', + ecmaVersion: 2020, + sourceType: 'module', + lib: ['es2020'], + }, + plugins: ['prettier', 'jsdoc', 'security', '@typescript-eslint'], + extends: [ + 'prettier', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:jsdoc/recommended', + 'plugin:security/recommended', + 'plugin:prettier/recommended', + ], + // add your custom rules here + rules: { + 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', + 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', + }, +}; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..79b8228f8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +name: ci + +on: + push: + branches: + - main + - master + - dev + pull_request_target: + branches: + - main + - master + - dev + +permissions: + checks: write + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + ci: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + node: [16, 17] + + steps: + - name: Check out repository (push) + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request_target' || github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }} + uses: actions/checkout@v2 + + - name: Check out repository (pull_request_target) + if: ${{ github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]' }} + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup node env 📦 + uses: actions/setup-node@v2.5.1 + with: + node-version: ${{ matrix.node }} + check-latest: true + registry-url: https://registry.npmjs.org + cache: 'npm' + + - name: Upgrade npm ✨ + run: npm i -g npm@latest + + - name: Install dependencies 🚀 + run: npm ci --prefer-offline --no-audit + + - name: Run linter(s) 👀 + uses: wearerequired/lint-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + git_name: github-actions[bot] + git_email: github-actions[bot]@users.noreply.github.com + continue_on_error: false + auto_fix: true + neutral_check_on_warning: true + eslint: true + eslint_extensions: js,ts + prettier: true + prettier_extensions: js,ts diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index ab14aab91..000000000 --- a/.jshintignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -coverage -reports diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 6b5af2b22..000000000 --- a/.jshintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "node": true, - "curly": true, - "eqeqeq": true, - "esversion": 9, - "freeze": true, - "immed": true, - "indent": 2, - "latedef": false, - "newcap": true, - "noarg": true, - "noempty": true, - "nonbsp": true, - "nonew": true, - "plusplus": false, - "quotmark": "single", - "undef": true, - "unused": false, - "maxparams": 4, - "maxdepth": 4, - "maxlen": 140 -} diff --git a/package.json b/package.json index 596b931c4..42ae7b334 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,13 @@ "ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao", "coverage": "node_modules/.bin/istanbul cover test/unit/run.js", "docs": "./bin/generate-docs", - "lint": "jshint .", + "lint": "npm run lint:eslint && npm run lint:prettier", + "lintfix": "npm run lint:eslint:fix && npm run lint:prettier:fix", + "lint:js": "npm run lint:eslint && npm run lint:prettier", + "lint:eslint": "eslint \"{,!(node_modules|dist|static)/**/}*.{js,ts}\" --ignore-path .gitignore", + "lint:eslint:fix": "eslint --fix \"{,!(node_modules|dist|static)/**/}*.{js,ts}\" --ignore-path .gitignore", + "lint:prettier": "prettier --check \"{,!(node_modules|dist|static)/**/}*.{js,ts}\" --ignore-path .gitignore", + "lint:prettier:fix": "prettier --write \"{,!(node_modules|dist|static)/**/}*.{js,ts}\" --ignore-path .gitignore", "start": "./bin/start", "test": "npm run unit", "ci": "npm test", @@ -67,12 +73,20 @@ "through2": "^3.0.0" }, "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.9.0", + "@typescript-eslint/parser": "^5.9.0", "ciao": "^2.0.0", "difflet": "^1.0.1", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-jsdoc": "^37.5.1", + "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-security": "^1.4.0", "istanbul": "^0.4.2", "jshint": "^2.10.1", "pelias-mock-logger": "^1.3.0", "precommit-hook": "^3.0.0", + "prettier": "^2.5.1", "proxyquire": "^2.0.0", "tap-dot": "^2.0.0", "tape": "^5.1.1" diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 000000000..8d65ea282 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,13 @@ +module.exports = { + $schema: 'http://json.schemastore.org/prettierrc', + semi: true, + arrowParens: 'always', + singleQuote: true, + trailingComma: 'all', + bracketSpacing: true, + htmlWhitespaceSensitivity: 'css', + insertPragma: false, + tabWidth: 2, + useTabs: false, + endOfLine: 'lf', +};