From 6611be8e1ab5cbd5b6dc5fbe3dbfc849894653fd Mon Sep 17 00:00:00 2001 From: Rifat Nabi Date: Mon, 9 Sep 2019 23:59:41 +1000 Subject: [PATCH] Fix linting rule and add lint to workflow --- .babelrc | 2 ++ .eslintignore | 4 ++++ .eslintrc.js | 13 +++++++------ .github/workflows/main.yml | 19 +++++++++++++++++++ .prettierrc | 4 ++++ package.json | 7 ++----- src/validation-errors/additional-prop.js | 4 +--- src/validation-errors/enum.js | 4 ++-- yarn.lock | 19 +++++++++++++++++++ 9 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 .eslintignore create mode 100644 .prettierrc diff --git a/.babelrc b/.babelrc index 9de43857..bd768b3c 100644 --- a/.babelrc +++ b/.babelrc @@ -9,6 +9,7 @@ "node": "8" }, "useBuiltIns": "usage", + "corejs": 3, "loose": true } ] @@ -25,6 +26,7 @@ "node": "4" }, "useBuiltIns": "usage", + "corejs": 3, "loose": true } ] diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..4e7d2821 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +flow-typed/ +lib/ +node_modules/ +dist/ diff --git a/.eslintrc.js b/.eslintrc.js index 5730e266..ebc20037 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,17 +1,18 @@ module.exports = { + root: true, env: { es6: true, node: true, 'jest/globals': true, }, - extends: ['eslint:recommended', 'plugin:jest/recommended', 'prettier'], + extends: [ + 'eslint:recommended', + 'plugin:jest/recommended', + 'plugin:prettier/recommended', + ], plugins: ['jest'], parserOptions: { - ecmaVersion: 2017, + ecmaVersion: 2018, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, }, - rules: {}, }; diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 56ac5f71..8529d708 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,3 +33,22 @@ jobs: if: matrix.node-version == '12.x' env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - name: Use Node.js 10.x + uses: actions/setup-node@v1 + with: + node-version: 10.x + + - name: Install Yarn + run: curl -o- -L https://yarnpkg.com/install.sh | bash + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Run ESLint + run: yarn eslint . diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..c1a6f667 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/package.json b/package.json index aa3dccbb..6dc281d4 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "eslint": "^6.3.0", "eslint-config-prettier": "^6.2.0", "eslint-plugin-jest": "^22.17.0", + "eslint-plugin-prettier": "^3.1.0", "flow-bin": "^0.107.0", "husky": "^3.0.5", "jest": "^24.9.0", @@ -59,7 +60,7 @@ "build": "yarn run clean && yarn build:modern && yarn build:legacy", "build:modern": "BABEL_ENV=modern babel src -d lib/modern/", "build:legacy": "BABEL_ENV=legacy babel src -d lib/legacy", - "prepare": "yarn build", + "prepublishOnly": "yarn build", "format": "prettier --write src/*.js src/**/*.js", "test": "jest", "test-ci": "jest --coverage --colors" @@ -68,9 +69,5 @@ "testMatch": [ "/src/**/__tests__/**/*.js" ] - }, - "prettier": { - "singleQuote": true, - "trailingComma": "es5" } } diff --git a/src/validation-errors/additional-prop.js b/src/validation-errors/additional-prop.js index 9dc5e6f8..e4431f65 100644 --- a/src/validation-errors/additional-prop.js +++ b/src/validation-errors/additional-prop.js @@ -13,9 +13,7 @@ export default class AdditionalPropValidationError extends BaseValidationError { return output.concat( this.getCodeFrame( - chalk`😲 {magentaBright ${ - params.additionalProperty - }} is not expected to be here!`, + chalk`😲 {magentaBright ${params.additionalProperty}} is not expected to be here!`, `${dataPath}/${params.additionalProperty}` ) ); diff --git a/src/validation-errors/enum.js b/src/validation-errors/enum.js index 2d9e9cbf..a73de1d2 100644 --- a/src/validation-errors/enum.js +++ b/src/validation-errors/enum.js @@ -60,8 +60,8 @@ export default class EnumValidationError extends BaseValidationError { value, weight: leven(value, currentValue.toString()), })) - .sort( - (x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0) + .sort((x, y) => + x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0 )[0]; return allowedValues.length === 1 || diff --git a/yarn.lock b/yarn.lock index 31531749..d9f5bd76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1758,6 +1758,13 @@ eslint-plugin-jest@^22.17.0: dependencies: "@typescript-eslint/experimental-utils" "^1.13.0" +eslint-plugin-prettier@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.0.tgz#8695188f95daa93b0dc54b249347ca3b79c4686d" + integrity sha512-XWX2yVuwVNLOUhQijAkXz+rMPPoCr7WFiAl8ig6I7Xn+pPVhDhzg4DxHpmbeb0iqjO9UronEA3Tb09ChnFVHHA== + dependencies: + prettier-linter-helpers "^1.0.0" + eslint-scope@^4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848" @@ -1994,6 +2001,11 @@ fast-deep-equal@^2.0.1: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + fast-json-stable-stringify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" @@ -3943,6 +3955,13 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + prettier@^1.14.2: version "1.18.2" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"