@bigbinary/eslint-plugin-neeto 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.
package/README.md CHANGED
@@ -75,6 +75,7 @@ of the issues identified in JavaScript code.
75
75
  - [no-buildurl-call-with-empty-params](./docs/src/rules/no-buildurl-call-with-empty-params.md)
76
76
  - [no-conditional-overlays](./docs/src/rules/no-conditional-overlays.md)
77
77
  - [no-deprecated-imports-from-zustand](./docs/src/rules/no-deprecated-imports-from-zustand.md)
78
+ - [no-edits-to-generated-translation-files](./docs/src/rules/no-edits-to-generated-translation-files.md)
78
79
  - [no-dangling-constants](./docs/src/rules/no-dangling-constants.md)
79
80
  - [no-globalProps-destructure](./docs/src/rules/no-globalProps-destructure.md)
80
81
  - [no-globalProps-reassignment](./docs/src/rules/no-globalProps-reassignment.md)
package/dist/index.js CHANGED
@@ -109,6 +109,7 @@
109
109
  "@bigbinary/neeto/no-buildurl-call-with-empty-params": "error",
110
110
  "@bigbinary/neeto/no-conditional-overlays": "error",
111
111
  "@bigbinary/neeto/no-deprecated-imports-from-zustand": "error",
112
+ "@bigbinary/neeto/no-edits-to-generated-translation-files": "error",
112
113
  "@bigbinary/neeto/no-dangling-constants": "error",
113
114
  "@bigbinary/neeto/no-excess-function-arguments": "warn",
114
115
  "@bigbinary/neeto/no-globalProps-destructure": "error",
@@ -283,7 +284,7 @@
283
284
  }
284
285
  });
285
286
 
286
- var version = "1.8.3";
287
+ var version = "1.8.4";
287
288
  var packageJson = {
288
289
  version: version};
289
290
 
@@ -313,6 +314,8 @@
313
314
  const REACT_QUERY_DIRECTORY = "app/javascript/src/hooks/reactQuery";
314
315
  const ROUTES_FILE_PATH = "app/javascript/src/routes.js";
315
316
  const COMPONENTS_DIRECTORY = "app/javascript/src/components";
317
+ const TRANSLATIONS_DIRECTORY = "app/javascript/src/translations";
318
+ const TRANSLATION_SOURCE_LOCALE = "en";
316
319
  const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "@bigbinary/neeto-utils"];
317
320
  const TYPES = {
318
321
  ARRAY_EXPRESSION: "ArrayExpression",
@@ -543,6 +546,7 @@
543
546
  const HELP_URL_INCORRECT_FORMAT = "Incorrect help URL format. Please use the 'help.neeto<product>.com' format instead of 'neeto<product>help.neetokb.com'.";
544
547
  const INVALID_SWITCH_CHILD_MESSAGE = "Switch component can only contain Route, Redirect, or PrivateRoute as direct children";
545
548
  const PREFER_RADIO_BUTTONS_FOR_FEW_OPTIONS = "Consider using Radio buttons instead of Dropdown/Select when there are fewer than 4 options.";
549
+ const NO_EDITS_TO_GENERATED_TRANSLATION_FILES = "This translation file is auto-generated. Only edit 'en.json'; translations for all other locales are generated from it automatically. Please revert your changes in this file.";
546
550
 
547
551
  const PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
548
552
 
@@ -714,6 +718,19 @@
714
718
  return filename.startsWith(componentsDirectory);
715
719
  };
716
720
 
721
+ /**
722
+ * Checks if the file is an auto-generated translation file, i.e. a JSON locale
723
+ * file inside the `translations` directory other than the source locale
724
+ * (en.json), which is the only file meant to be edited by hand.
725
+ * @param {Object} context eslint context
726
+ * @returns true if the file is a generated (non-source) translation file
727
+ */
728
+ const isGeneratedTranslationFile = context => {
729
+ const [filename, extension] = getFilenameAndExtension(context);
730
+ const translationsDirectory = path$1.resolve(TRANSLATIONS_DIRECTORY);
731
+ return context.getFilename().startsWith(translationsDirectory) && extension === "json" && filename !== TRANSLATION_SOURCE_LOCALE;
732
+ };
733
+
717
734
  /**
718
735
  * Checks if the specified package is imported or not
719
736
  * using the package name or any alias
@@ -787,8 +804,7 @@
787
804
  const parseJsonData = filePath => {
788
805
  try {
789
806
  const jsonData = fs.readFileSync(filePath).toString();
790
- const parsedJsonData = JSON.parse(removeComments(jsonData));
791
- return parsedJsonData;
807
+ return JSON.parse(removeComments(jsonData));
792
808
  } catch {
793
809
  return {};
794
810
  }
@@ -7516,6 +7532,26 @@
7516
7532
  })
7517
7533
  };
7518
7534
 
7535
+ var noEditsToGeneratedTranslationFiles = {
7536
+ meta: {
7537
+ type: "problem",
7538
+ docs: {
7539
+ url: "https://github.com/neetozone/eslint-plugin-neeto/blob/main/docs/src/rules/no-edits-to-generated-translation-files.md",
7540
+ description: "Disallows manual edits to auto-generated translation files. Only the source locale (en.json) should be edited by hand."
7541
+ }
7542
+ },
7543
+ create: context => ({
7544
+ Program(node) {
7545
+ if (isGeneratedTranslationFile(context)) {
7546
+ context.report({
7547
+ node,
7548
+ message: NO_EDITS_TO_GENERATED_TRANSLATION_FILES
7549
+ });
7550
+ }
7551
+ }
7552
+ })
7553
+ };
7554
+
7519
7555
  const nonDefaultParam = ({
7520
7556
  type
7521
7557
  }) => type !== TYPES.ASSIGNMENT_PATTERN;
@@ -12215,6 +12251,7 @@
12215
12251
  "no-axios-import-outside-apis": noAxiosImportOutsideApis,
12216
12252
  "no-conditional-overlays": noConditionalOverlays,
12217
12253
  "no-deprecated-imports-from-zustand": noDeprecatedImportsFromZustand,
12254
+ "no-edits-to-generated-translation-files": noEditsToGeneratedTranslationFiles,
12218
12255
  "no-excess-function-arguments": noExcessFunctionArguments,
12219
12256
  "no-dangling-constants": noDanglingConstants,
12220
12257
  "no-globalProps-destructure": noGlobalPropsDestructure,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {