diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..a45e89e5 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,25 @@ +const { config } = require('@dhis2/cli-style') + +module.exports = { + extends: [config.eslintReact], + rules: { + curly: 'warn', + 'getter-return': 'warn', + 'import/extensions': 'warn', + 'import/order': 'warn', + 'max-params': 'warn', + 'no-cond-assign': 'warn', + 'no-control-regex': 'warn', + 'no-empty': 'warn', + 'no-prototype-builtins': 'warn', + 'no-self-assign': 'warn', + 'no-regex-spaces': 'warn', + 'no-undef': 'warn', + 'no-unreachable': 'warn', + 'no-unsafe-finally': 'warn', + 'no-unused-vars': 'warn', + 'no-useless-escape': 'warn', + 'prefer-const': 'warn', + 'react/display-name': 'warn', + }, +} diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 00000000..50ae359a --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn d2-style check --staged diff --git a/.hooks/pre-push b/.hooks/pre-push new file mode 100755 index 00000000..f077c917 --- /dev/null +++ b/.hooks/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn test diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index 6d51ebfd..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1 +0,0 @@ -yarn d2-style check --staged diff --git a/.prettierrc.js b/.prettierrc.js index b51d4161..0ea40ae5 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,7 @@ +const { config } = require('@dhis2/cli-style') + module.exports = { + ...require(config.prettier), printWidth: 80, tabWidth: 4, useTabs: false, @@ -6,7 +9,7 @@ module.exports = { singleQuote: true, trailingComma: 'es5', bracketSpacing: true, - jsxBracketSameLine: false, + bracketSameLine: false, jsxSingleQuote: false, arrowParens: 'avoid', rangeStart: 0, diff --git a/package.json b/package.json index b4ce33e4..a538cf7c 100644 --- a/package.json +++ b/package.json @@ -46,20 +46,21 @@ "babel-jest": "^29.7.0", "babel-plugin-transform-import-meta": "^2.2.1", "concurrently": "^7.6.0", - "husky": "^9.0.11", "identity-obj-proxy": "^3.0.0", "jest": "^27.5.1", "rimraf": "^5.0.7" }, "scripts": { - "format": "d2-style apply js --all --no-stage", + "lint": "yarn d2-style check", + "lint:staged": "yarn lint --staged", + "format": "yarn d2-style apply", + "format:staged": "yarn format --staged", "clean": "rimraf ./build/*", "build:commonjs": "BABEL_ENV=commonjs babel src --out-dir ./build/cjs --copy-files --verbose", "build:modules": "BABEL_ENV=modules babel src --out-dir ./build/es --copy-files --verbose", "build": "NODE_ENV=production yarn clean && yarn build:commonjs && yarn build:modules", "watch": "NODE_ENV=development yarn clean && concurrently -n watch-cjs,watch-es \"yarn build:commonjs --watch\" \"yarn build:modules --watch\"", - "test": "jest src/*", - "prepare": "husky" + "test": "jest src/*" }, "jest": { "setupFiles": [ diff --git a/src/utils/__tests__/numbers.spec.js b/src/utils/__tests__/numbers.spec.js index 133b02b0..ef0f3233 100644 --- a/src/utils/__tests__/numbers.spec.js +++ b/src/utils/__tests__/numbers.spec.js @@ -3,8 +3,6 @@ import { getPrecision, setPrecision, kmToMiles, - squareMetersToHectares, - squareMetersToAcres, } from '../numbers' describe('numbers', () => { diff --git a/yarn.lock b/yarn.lock index 63871e5b..a6ce1b81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4158,11 +4158,6 @@ husky@^7.0.2: resolved "https://registry.yarnpkg.com/husky/-/husky-7.0.4.tgz#242048245dc49c8fb1bf0cc7cfb98dd722531535" integrity sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ== -husky@^9.0.11: - version "9.0.11" - resolved "https://registry.yarnpkg.com/husky/-/husky-9.0.11.tgz#fc91df4c756050de41b3e478b2158b87c1e79af9" - integrity sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw== - iconv-lite@0.4.24, iconv-lite@^0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -6716,7 +6711,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -6742,15 +6737,6 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -6799,7 +6785,7 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -6820,13 +6806,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.1.tgz#61740a08ce36b61e50e65653f07060d000975fb2" @@ -7521,7 +7500,7 @@ word-wrap@^1.2.3, word-wrap@~1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -7539,15 +7518,6 @@ wrap-ansi@^5.1.0: string-width "^3.0.0" strip-ansi "^5.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"