chayns-toolkit 2.0.0-beta.1 → 2.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/babel.js CHANGED
@@ -1,75 +1,70 @@
1
- const { declare } = require("@babel/helper-plugin-utils")
2
-
3
- module.exports = declare((api, options) => {
4
- api.assertVersion(7)
5
-
6
- const env = process.env.BABEL_ENV || process.env.NODE_ENV
7
-
8
- const {
9
- typescriptSupport = false,
10
- flowSupport = false,
11
- transformChaynsComponentsImports = true,
12
- transpileModules = false,
13
- reactRefreshSupport = true,
14
- } = options
15
-
16
- if (env === "test") {
17
- return { presets: [["@babel/env", { targets: { node: "current" } }]] }
18
- }
19
-
20
- return {
21
- presets: [
22
- [
23
- "@babel/env",
24
- {
25
- loose: true,
26
- bugfixes: true,
27
- modules: transpileModules,
28
- exclude: ["transform-typeof-symbol"],
29
- useBuiltIns: "usage",
30
- corejs: 3,
31
- },
32
- ],
33
- [
34
- "@babel/react",
35
- {
36
- runtime: "automatic",
37
- development: env !== "production",
38
- },
39
- ],
40
- flowSupport && "@babel/flow",
41
- typescriptSupport && "@babel/typescript",
42
- ].filter(Boolean),
43
- plugins: [
44
- transformChaynsComponentsImports && [
45
- "transform-imports",
46
- {
47
- "chayns-components": {
48
- // eslint-disable-next-line global-require
49
- transform: require("chayns-components/lib/utils/babel/resolveAbsoluteImport"),
50
- preventFullImport: true,
51
- },
52
- },
53
- ],
54
- "macros",
55
- "optimize-clsx",
56
- [
57
- "@babel/transform-runtime",
58
- {
59
- // eslint-disable-next-line global-require
60
- version: require("@babel/runtime/package.json").version,
61
- corejs: false,
62
- regenerator: true,
63
- },
64
- ],
65
- typescriptSupport && [
66
- "@babel/proposal-decorators",
67
- { legacy: true },
68
- ],
69
- env === "production" && "transform-react-remove-prop-types",
70
- reactRefreshSupport &&
71
- env !== "production" &&
72
- "react-refresh/babel",
73
- ].filter(Boolean),
74
- }
75
- })
1
+ const { declare } = require("@babel/helper-plugin-utils")
2
+
3
+ module.exports = declare((api, options) => {
4
+ api.assertVersion(7)
5
+
6
+ const env = process.env.BABEL_ENV || process.env.NODE_ENV
7
+
8
+ const {
9
+ typescriptSupport = false,
10
+ flowSupport = false,
11
+ transpileModules = false,
12
+ reactRefreshSupport = true,
13
+ } = options
14
+
15
+ if (env === "test") {
16
+ return { presets: [["@babel/env", { targets: { node: "current" } }]] }
17
+ }
18
+
19
+ return {
20
+ presets: [
21
+ [
22
+ "@babel/env",
23
+ {
24
+ loose: true,
25
+ bugfixes: true,
26
+ modules: transpileModules,
27
+ exclude: ["transform-typeof-symbol"],
28
+ useBuiltIns: "usage",
29
+ corejs: 3,
30
+ },
31
+ ],
32
+ [
33
+ "@babel/react",
34
+ {
35
+ runtime: "automatic",
36
+ development: env !== "production",
37
+ },
38
+ ],
39
+ flowSupport && "@babel/flow",
40
+ typescriptSupport && "@babel/typescript",
41
+ ].filter(Boolean),
42
+ plugins: [
43
+ "macros",
44
+ "optimize-clsx",
45
+ [
46
+ "@babel/transform-runtime",
47
+ {
48
+ // eslint-disable-next-line global-require
49
+ version: require("@babel/runtime/package.json").version,
50
+ corejs: false,
51
+ regenerator: true,
52
+ },
53
+ ],
54
+ typescriptSupport && [
55
+ "@babel/proposal-decorators",
56
+ { legacy: true },
57
+ ],
58
+ env === "production" && "transform-react-remove-prop-types",
59
+ reactRefreshSupport &&
60
+ env !== "production" &&
61
+ "react-refresh/babel",
62
+ [
63
+ "@babel/plugin-transform-spread",
64
+ {
65
+ loose: false,
66
+ },
67
+ ],
68
+ ].filter(Boolean),
69
+ }
70
+ })
package/cli.js CHANGED
@@ -1,3 +1,3 @@
1
- #! /usr/bin/env node
1
+ #! /usr/bin/env node
2
2
 
3
3
  require("./lib/cli.js")
@@ -0,0 +1,65 @@
1
+ const path = require("path")
2
+ const javascriptRules = require("./javascriptRules")
3
+ const sharedRules = require("./sharedRules")
4
+ const typescriptRules = require("./typescriptRules")
5
+
6
+ // eslint-disable-next-line import/no-dynamic-require
7
+ const packageJson = require(path.resolve("package.json"))
8
+
9
+ const usesTypeScript = Object.keys({
10
+ ...packageJson.dependencies,
11
+ ...packageJson.devDependencies,
12
+ }).includes("typescript")
13
+
14
+ module.exports = {
15
+ env: {
16
+ browser: true,
17
+ es6: true,
18
+ },
19
+ extends: ["airbnb", "airbnb/hooks", "prettier"],
20
+ globals: { chayns: true },
21
+ rules: { ...sharedRules, ...javascriptRules },
22
+ parser: "@babel/eslint-parser",
23
+ parserOptions: {
24
+ requireConfigFile: false,
25
+ },
26
+ settings: {
27
+ "import/resolver": {
28
+ typescript: { project: "@(jsconfig|tsconfig).json" },
29
+ },
30
+ "import/extensions": [".js", ".jsx", ".ts", ".tsx"],
31
+ },
32
+ overrides: [
33
+ usesTypeScript && {
34
+ files: ["**/*.ts?(x)"],
35
+ extends: [
36
+ "airbnb-typescript",
37
+ "airbnb/hooks",
38
+ "plugin:@typescript-eslint/recommended",
39
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
40
+ "prettier",
41
+ "plugin:import/typescript",
42
+ ],
43
+ rules: {
44
+ ...sharedRules,
45
+ ...typescriptRules,
46
+ },
47
+ parserOptions: {
48
+ project: "./tsconfig.json",
49
+ },
50
+ },
51
+ {
52
+ files: ["**/*.@(test|spec).@(js|jsx|ts|tsx)"],
53
+ env: { "jest/globals": true },
54
+ plugins: ["jest"],
55
+ rules: {
56
+ ...sharedRules,
57
+ "jest/no-disabled-tests": "warn",
58
+ "jest/no-focused-tests": "error",
59
+ "jest/no-identical-title": "error",
60
+ "jest/prefer-to-have-length": "warn",
61
+ "jest/valid-expect": "error",
62
+ },
63
+ },
64
+ ].filter(Boolean),
65
+ }
@@ -0,0 +1,8 @@
1
+ const javascriptRules = {
2
+ "no-use-before-define": [
3
+ "error",
4
+ { functions: false, classes: false, variables: false },
5
+ ],
6
+ }
7
+
8
+ module.exports = javascriptRules
@@ -0,0 +1,32 @@
1
+ const sharedRules = {
2
+ "import/extensions": [
3
+ "error",
4
+ "always",
5
+ { js: "never", jsx: "never", ts: "never", tsx: "never" },
6
+ ],
7
+ "import/no-unresolved": ["error", { ignore: ["chayns-components"] }],
8
+ "import/prefer-default-export": "off",
9
+ "jsx-a11y/anchor-has-content": "off",
10
+ "jsx-a11y/anchor-is-valid": "off",
11
+ "jsx-a11y/click-events-have-key-events": "off",
12
+ "jsx-a11y/heading-has-content": "off",
13
+ "jsx-a11y/href-no-hash": "off",
14
+ "jsx-a11y/no-noninteractive-element-interactions": "off",
15
+ "jsx-a11y/no-static-element-interactions": "off",
16
+ "no-console": ["warn", { allow: ["warn", "error"] }],
17
+ "no-param-reassign": [
18
+ "error",
19
+ { ignorePropertyModificationsFor: ["draft"], props: true },
20
+ ],
21
+ "no-plusplus": "off",
22
+ "no-restricted-imports": [
23
+ "error",
24
+ {
25
+ message: "Use 'chayns-components' instead to enable tree-shaking.",
26
+ name: "chayns-components/lib",
27
+ },
28
+ ],
29
+ "react/no-danger": "off",
30
+ }
31
+
32
+ module.exports = sharedRules
@@ -0,0 +1,20 @@
1
+ const typescriptRules = {
2
+ "react/prop-types": "off",
3
+ "react/require-default-props": "off",
4
+ "@typescript-eslint/no-use-before-define": [
5
+ "error",
6
+ { functions: false, classes: false, variables: false, enums: false },
7
+ ],
8
+ "@typescript-eslint/ban-ts-comment": [
9
+ "error",
10
+ {
11
+ "ts-expect-error": "allow-with-description",
12
+ "ts-ignore": true,
13
+ "ts-nocheck": true,
14
+ "ts-check": true,
15
+ minimumDescriptionLength: 4,
16
+ },
17
+ ],
18
+ }
19
+
20
+ module.exports = typescriptRules