@bigbinary/neeto-commons-rn 1.8.4 → 1.8.5

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.
@@ -0,0 +1,299 @@
1
+ // Shared ESLint 9 flat config for neeto React Native apps.
2
+ //
3
+ // Usage in an app's eslint.config.js:
4
+ //
5
+ // const neetoRNConfig = require("@bigbinary/neeto-commons-rn/eslint-config");
6
+ // const aliases = require("./aliases.json");
7
+ //
8
+ // module.exports = neetoRNConfig({ aliases });
9
+ //
10
+ // The plugins are resolved from the consuming app's node_modules — install
11
+ // the packages listed under peerDependencies (lint group) as devDependencies.
12
+ const babelParser = require("@babel/eslint-parser");
13
+ const js = require("@eslint/js");
14
+ const prettierConfig = require("eslint-config-prettier");
15
+ const importPlugin = require("eslint-plugin-import");
16
+ const prettierPlugin = require("eslint-plugin-prettier");
17
+ const promisePlugin = require("eslint-plugin-promise");
18
+ const reactPlugin = require("eslint-plugin-react");
19
+ const reactHooksPlugin = require("eslint-plugin-react-hooks");
20
+ const reactNativePlugin = require("eslint-plugin-react-native");
21
+ const unusedImportsPlugin = require("eslint-plugin-unused-imports");
22
+ const globals = require("globals");
23
+
24
+ const neetoPlugin = {
25
+ rules: {
26
+ "no-dangling-constants": require("./rules/no-dangling-constants"),
27
+ "no-redundant-string-templates": require("./rules/no-redundant-string-templates"),
28
+ },
29
+ };
30
+
31
+ const DEFAULT_IGNORES = [
32
+ "node_modules/**",
33
+ "android/**",
34
+ "ios/**",
35
+ "vendor/**",
36
+ "coverage/**",
37
+ "patches/**",
38
+ "**/*.json",
39
+ ];
40
+
41
+ module.exports = ({ aliases = {}, ignores = [] } = {}) => [
42
+ {
43
+ ignores: [...DEFAULT_IGNORES, ...ignores],
44
+ },
45
+ js.configs.recommended,
46
+ reactPlugin.configs.flat.recommended,
47
+ promisePlugin.configs["flat/recommended"],
48
+ {
49
+ files: ["**/*.{js,jsx}"],
50
+ languageOptions: {
51
+ parser: babelParser,
52
+ ecmaVersion: "latest",
53
+ sourceType: "module",
54
+ parserOptions: {
55
+ ecmaFeatures: { jsx: true },
56
+ },
57
+ globals: {
58
+ ...globals.browser,
59
+ ...globals.node,
60
+ ...globals.es2021,
61
+ ...globals.jest,
62
+ ...(reactNativePlugin.environments?.["react-native"]?.globals ?? {}),
63
+ Atomics: "readonly",
64
+ SharedArrayBuffer: "readonly",
65
+ // Makes logger function available everywhere. Else eslint will complain of undef-var.
66
+ logger: "readonly",
67
+ globalProps: "readonly",
68
+ },
69
+ },
70
+ plugins: {
71
+ react: reactPlugin,
72
+ "react-native": reactNativePlugin,
73
+ import: importPlugin,
74
+ "react-hooks": reactHooksPlugin,
75
+ "@bigbinary/neeto": neetoPlugin,
76
+ "unused-imports": unusedImportsPlugin,
77
+ prettier: prettierPlugin,
78
+ },
79
+ settings: {
80
+ react: {
81
+ version: "detect",
82
+ },
83
+ "import/resolver": {
84
+ "babel-module": {
85
+ root: ["."],
86
+ alias: aliases,
87
+ },
88
+ },
89
+ "react-native/style-sheet-object-names": ["StyleSheet"],
90
+ },
91
+ rules: {
92
+ // Disable stylistic rules that conflict with Prettier, then let
93
+ // prettier/prettier report formatting drift.
94
+ ...prettierConfig.rules,
95
+ "prettier/prettier": "error",
96
+
97
+ "@bigbinary/neeto/no-dangling-constants": 2,
98
+ "@bigbinary/neeto/no-redundant-string-templates": 2,
99
+ "import/no-unresolved": 2,
100
+ "require-await": 2,
101
+ "import/no-anonymous-default-export": 2,
102
+ "no-unused-vars": [
103
+ "error",
104
+ {
105
+ args: "all",
106
+ argsIgnorePattern: "^_",
107
+ destructuredArrayIgnorePattern: "^_",
108
+ caughtErrors: "all",
109
+ },
110
+ ],
111
+ "no-undef": "error",
112
+ // Dont use console statements. Use logger which babel will remove during bundling.
113
+ "no-console": "error",
114
+ "consistent-return": "error",
115
+ "padding-line-between-statements": [
116
+ "error",
117
+ { blankLine: "always", prev: "if", next: ["if", "return"] },
118
+ { blankLine: "always", prev: "*", next: "return" },
119
+ {
120
+ blankLine: "always",
121
+ prev: [
122
+ "block",
123
+ "multiline-block-like",
124
+ "function",
125
+ "iife",
126
+ "multiline-const",
127
+ "multiline-expression",
128
+ ],
129
+ next: ["function", "iife", "multiline-const", "multiline-expression"],
130
+ },
131
+ ],
132
+ curly: ["error", "multi-line"],
133
+ "no-else-return": "error",
134
+ "comma-dangle": [
135
+ "error",
136
+ {
137
+ arrays: "always-multiline",
138
+ objects: "always-multiline",
139
+ imports: "always-multiline",
140
+ exports: "always-multiline",
141
+ functions: "never",
142
+ },
143
+ ],
144
+ "prefer-const": "error",
145
+ eqeqeq: "error",
146
+ "no-unsafe-optional-chaining": "error",
147
+ "unused-imports/no-unused-imports": "error",
148
+ "no-nested-ternary": "warn",
149
+ "arrow-body-style": ["error", "as-needed"],
150
+ "prefer-template": "error",
151
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
152
+ "object-shorthand": [
153
+ "error",
154
+ "always",
155
+ { avoidQuotes: true, ignoreConstructors: true },
156
+ ],
157
+ "prefer-arrow-callback": ["error", { allowUnboundThis: true }],
158
+ "no-duplicate-imports": ["error", { includeExports: true }],
159
+ "no-implicit-coercion": ["error", { allow: ["!!"] }],
160
+ "no-var": "error",
161
+
162
+ // Promise hygiene.
163
+ "promise/prefer-await-to-then": 2,
164
+ "promise/no-nesting": 2,
165
+ "promise/prefer-await-to-callbacks": 2,
166
+ "promise/no-new-statics": "error",
167
+
168
+ // Imports.
169
+ "import/order": [
170
+ "error",
171
+ {
172
+ "newlines-between": "always",
173
+ alphabetize: { order: "asc", caseInsensitive: true },
174
+ warnOnUnassignedImports: true,
175
+ groups: [
176
+ "builtin",
177
+ "external",
178
+ "internal",
179
+ "index",
180
+ "sibling",
181
+ "parent",
182
+ "object",
183
+ "type",
184
+ ],
185
+ pathGroups: [
186
+ {
187
+ pattern: "react+(-native|)",
188
+ group: "external",
189
+ position: "before",
190
+ },
191
+ ],
192
+ // Ignore react imports so that they're always ordered to the top of the file.
193
+ pathGroupsExcludedImportTypes: ["react", "react-native"],
194
+ },
195
+ ],
196
+ "import/prefer-default-export": "off",
197
+ "import/no-cycle": ["error", { maxDepth: 1, ignoreExternal: true }],
198
+ "import/no-useless-path-segments": ["error", { noUselessIndex: true }],
199
+ "import/export": "error",
200
+ "import/no-mutable-exports": "error",
201
+ "import/first": "error",
202
+ "import/newline-after-import": ["error", { count: 1 }],
203
+ "import/extensions": [
204
+ "error",
205
+ "never",
206
+ {
207
+ ignorePackages: true,
208
+ pattern: { json: "always", mp3: "always" },
209
+ },
210
+ ],
211
+
212
+ // React.
213
+ "react/prop-types": "off",
214
+ "react/no-unescaped-entities": "off",
215
+ "react/display-name": "error",
216
+ "react/no-access-state-in-setstate": "error",
217
+ "react/no-danger": "warn",
218
+ "react/no-danger-with-children": "warn",
219
+ "react/no-unused-prop-types": "error",
220
+ "react/jsx-key": "error",
221
+ "react/jsx-no-duplicate-props": "error",
222
+ "react/jsx-no-undef": "error",
223
+ "react/jsx-pascal-case": [
224
+ "error",
225
+ { allowNamespace: true, ignore: ["FAB"] },
226
+ ],
227
+ "react/jsx-uses-react": "error",
228
+ "react/jsx-uses-vars": "error",
229
+ "react/jsx-no-useless-fragment": ["error", { allowExpressions: true }],
230
+ "react/function-component-definition": [
231
+ "error",
232
+ {
233
+ namedComponents: "arrow-function",
234
+ unnamedComponents: "arrow-function",
235
+ },
236
+ ],
237
+ "react/self-closing-comp": [
238
+ "error",
239
+ {
240
+ component: true,
241
+ html: true,
242
+ },
243
+ ],
244
+ "react/jsx-wrap-multilines": [
245
+ "error",
246
+ {
247
+ declaration: "parens-new-line",
248
+ assignment: "parens-new-line",
249
+ return: "parens-new-line",
250
+ arrow: "parens-new-line",
251
+ condition: "parens-new-line",
252
+ logical: "parens-new-line",
253
+ prop: "ignore",
254
+ },
255
+ ],
256
+ "react/jsx-filename-extension": ["error", { allow: "as-needed" }],
257
+ "react/jsx-boolean-value": "error",
258
+ "react/hook-use-state": "error",
259
+ "react/jsx-sort-props": [
260
+ "error",
261
+ {
262
+ callbacksLast: true,
263
+ shorthandFirst: true,
264
+ multiline: "last",
265
+ reservedFirst: false,
266
+ locale: "auto",
267
+ },
268
+ ],
269
+ "react/jsx-curly-brace-presence": [
270
+ "error",
271
+ {
272
+ props: "never",
273
+ children: "never",
274
+ propElementValues: "always",
275
+ },
276
+ ],
277
+ "react/jsx-newline": ["error", { prevent: true }],
278
+ // allowAsProps: React Navigation (tabBarIcon) and neetoui-rn
279
+ // (SuffixIcon, RightComponent) take render-prop components.
280
+ "react/no-unstable-nested-components": ["error", { allowAsProps: true }],
281
+
282
+ "react-hooks/rules-of-hooks": "error",
283
+ "react-hooks/exhaustive-deps": "warn",
284
+
285
+ "react-native/no-unused-styles": 2,
286
+ "react-native/split-platform-components": 1,
287
+ "react-native/no-inline-styles": 1,
288
+ "react-native/no-raw-text": 0,
289
+ "react-native/no-single-element-style-arrays": 1,
290
+ },
291
+ },
292
+ {
293
+ files: ["*.config.js", ".prettierrc.js", "babel.config.js"],
294
+ rules: {
295
+ "import/order": "off",
296
+ "react-hooks/rules-of-hooks": "off",
297
+ },
298
+ },
299
+ ];
@@ -0,0 +1,35 @@
1
+ // Vendored from neetozone/eslint-plugin-neeto (src/lib/rules/constants/
2
+ // no-dangling-constants.js) so the plugin — and its hard dependency on
3
+ // neeto-commons-frontend — is not needed for the two rules this app uses.
4
+ const path = require("path");
5
+
6
+ const CONSTANT_CASE_PATTERN = /^[A-Z0-9_]*$/;
7
+ const CONSTANTS_FILES = [/constants\//, /.*constants.(js|jsx)$/i];
8
+
9
+ const isConstantsFile = filename =>
10
+ CONSTANTS_FILES.some(pattern => pattern.test(path.resolve(filename)));
11
+
12
+ module.exports = {
13
+ meta: {
14
+ type: "suggestion",
15
+ docs: {
16
+ url: "https://github.com/neetozone/eslint-plugin-neeto/blob/main/docs/src/rules/no-dangling-constants.md",
17
+ description:
18
+ "Indicates that any constant outside a constant.[js|jsx] file should be moved to a constant.[js|jsx] file.",
19
+ },
20
+ },
21
+ create: context => ({
22
+ VariableDeclaration(node) {
23
+ if (isConstantsFile(context.filename)) return;
24
+ if (node.kind !== "const") return;
25
+
26
+ const name = node.declarations[0]?.id?.name;
27
+ if (!name || !CONSTANT_CASE_PATTERN.test(name)) return;
28
+
29
+ context.report({
30
+ node,
31
+ message: `Move the constant ${name} to a constants.js file.`,
32
+ });
33
+ },
34
+ }),
35
+ };
@@ -0,0 +1,85 @@
1
+ // Vendored from neetozone/eslint-plugin-neeto (src/lib/rules/
2
+ // no-redundant-string-templates/) so the plugin — and its hard dependency on
3
+ // neeto-commons-frontend — is not needed for the two rules this app uses.
4
+ const CHARACTERS_TO_IGNORE_PATTERN = /[\r\n\t\f\v&><}"{'`\\]/;
5
+ const ENDS_WITH_SPACES_PATTERN = / +$/;
6
+ const STARTS_OR_ENDS_WITH_SPACES_PATTERN = /^ +| +$/;
7
+ const STARTS_WITH_SPACES_PATTERN = /^ +/;
8
+
9
+ const getCode = (context, node) =>
10
+ context.sourceCode.text.slice(node.range[0], node.range[1]);
11
+
12
+ const doQuasisHaveSpecialCharacters = node =>
13
+ node.quasis.some(quasi =>
14
+ CHARACTERS_TO_IGNORE_PATTERN.test(quasi.value.cooked)
15
+ );
16
+
17
+ const isExpressionOnly = node =>
18
+ node.expressions.length === 1 &&
19
+ node.quasis.length === 2 &&
20
+ node.quasis[0].value.cooked === "" &&
21
+ node.quasis[1].value.cooked === "";
22
+
23
+ const isInsideJsxElement = node =>
24
+ node.parent?.type === "JSXExpressionContainer" &&
25
+ ["JSXElement", "JSXFragment"].includes(node.parent.parent?.type) &&
26
+ !STARTS_WITH_SPACES_PATTERN.test(node.quasis[0]?.value.cooked ?? "") &&
27
+ !ENDS_WITH_SPACES_PATTERN.test(
28
+ node.quasis[node.quasis.length - 1]?.value.cooked ?? ""
29
+ );
30
+
31
+ const isReplaceableQuasisOnly = node =>
32
+ node.expressions.length === 0 &&
33
+ node.quasis.length === 1 &&
34
+ !STARTS_OR_ENDS_WITH_SPACES_PATTERN.test(node.quasis[0].value.cooked);
35
+
36
+ const getTemplateContent = (context, node) =>
37
+ node.expressions.reduce(
38
+ (acc, expression, index) =>
39
+ `${acc}{${getCode(context, expression)}}${
40
+ node.quasis[index + 1].value.cooked
41
+ }`,
42
+ node.quasis[0].value.cooked
43
+ );
44
+
45
+ const canBeReplacedWith = fix => `Can be replaced with: ${fix}`;
46
+
47
+ module.exports = {
48
+ meta: {
49
+ type: "problem",
50
+ docs: {
51
+ url: "https://github.com/neetozone/eslint-plugin-neeto/blob/main/docs/src/rules/no-redundant-string-templates.md",
52
+ description:
53
+ "Prevent usage of string templates as direct children of JSX components.",
54
+ },
55
+ fixable: "code",
56
+ },
57
+ create: context => ({
58
+ TemplateLiteral(node) {
59
+ if (doQuasisHaveSpecialCharacters(node)) return;
60
+
61
+ if (isExpressionOnly(node)) {
62
+ const fix = getCode(context, node.expressions[0]);
63
+ context.report({
64
+ node,
65
+ message: canBeReplacedWith(fix),
66
+ fix: fixer => fixer.replaceText(node, fix),
67
+ });
68
+ } else if (isInsideJsxElement(node)) {
69
+ const fix = getTemplateContent(context, node);
70
+ context.report({
71
+ node,
72
+ message: canBeReplacedWith(fix),
73
+ fix: fixer => fixer.replaceText(node.parent, fix),
74
+ });
75
+ } else if (isReplaceableQuasisOnly(node)) {
76
+ const fix = `"${node.quasis[0].value.cooked}"`;
77
+ context.report({
78
+ node,
79
+ message: canBeReplacedWith(fix),
80
+ fix: fixer => fixer.replaceText(node, fix),
81
+ });
82
+ }
83
+ },
84
+ }),
85
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-rn",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "main": ".",
5
5
  "files": [
6
6
  "api",
@@ -20,7 +20,6 @@
20
20
  "screens",
21
21
  "assets",
22
22
  "utils",
23
- "index.d.ts",
24
23
  "eslint-config"
25
24
  ],
26
25
  "husky": {