js-style-kit 0.5.3 → 0.6.1

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/dist/index.js CHANGED
@@ -17,6 +17,7 @@ var configNames = {
17
17
  nextjs: "nextjs",
18
18
  perfectionist: "perfectionist",
19
19
  preferArrowFunction: "prefer-arrow-function",
20
+ query: "@tanstack/query",
20
21
  react: "react",
21
22
  reactRefresh: "react-refresh",
22
23
  storybook: "storybook:stories",
@@ -28,6 +29,7 @@ var configNames = {
28
29
  unicorn: "unicorn"
29
30
  };
30
31
  var pluginPrefixMap = /* @__PURE__ */ new Map([
32
+ ["@tanstack/query", configNames.query],
31
33
  ["@typescript-eslint", configNames.typescript],
32
34
  ["import", configNames.import],
33
35
  ["import-x", configNames.import],
@@ -827,6 +829,32 @@ var processCustomRules = (customRules) => {
827
829
  }, {});
828
830
  };
829
831
 
832
+ // src/eslint/query/config.ts
833
+ import queryPlugin from "@tanstack/eslint-plugin-query";
834
+
835
+ // src/eslint/query/rules.ts
836
+ var queryRules = {
837
+ "@tanstack/query/exhaustive-deps": "warn",
838
+ "@tanstack/query/infinite-query-property-order": "warn",
839
+ "@tanstack/query/mutation-property-order": "warn",
840
+ "@tanstack/query/no-rest-destructuring": "warn",
841
+ "@tanstack/query/no-unstable-deps": "warn",
842
+ "@tanstack/query/no-void-query-fn": "warn",
843
+ "@tanstack/query/stable-query-client": "warn"
844
+ };
845
+
846
+ // src/eslint/query/config.ts
847
+ var queryConfig = (customRules) => ({
848
+ name: configNames.query,
849
+ plugins: {
850
+ "@tanstack/query": queryPlugin
851
+ },
852
+ rules: {
853
+ ...queryRules,
854
+ ...customRules ?? {}
855
+ }
856
+ });
857
+
830
858
  // src/eslint/react-refresh/config.ts
831
859
  import reactRefresh from "eslint-plugin-react-refresh";
832
860
 
@@ -863,7 +891,11 @@ import pluginReactHooks from "eslint-plugin-react-hooks";
863
891
  import globals from "globals";
864
892
 
865
893
  // src/eslint/react/rules.ts
866
- var reactRules = (functionStyle, typescript) => {
894
+ var reactRules = ({
895
+ functionStyle,
896
+ reactCompiler,
897
+ typescript
898
+ }) => {
867
899
  const functionStyleMap = {
868
900
  arrow: "arrow-function",
869
901
  declaration: "function-declaration",
@@ -874,9 +906,39 @@ var reactRules = (functionStyle, typescript) => {
874
906
  * Disabled in favor of TypeScript for type checking
875
907
  */
876
908
  ...typescript ? {} : { "react/prop-types": "warn" },
909
+ /**
910
+ * Core React Hooks rules
911
+ */
877
912
  "react-hooks/exhaustive-deps": "warn",
878
- "react-hooks/react-compiler": "warn",
879
913
  "react-hooks/rules-of-hooks": "warn",
914
+ /**
915
+ * React compiler rules
916
+ */
917
+ ...reactCompiler ? {
918
+ /**
919
+ * Does not seem to be working, and overlaps with static-components
920
+ */
921
+ // "react-hooks/component-hook-factories": "warn",
922
+ /**
923
+ * seems unecessary unless you're rolling your own React setup, users can always enable
924
+ */
925
+ // "react-hooks/config": "warn",
926
+ "react-hooks/error-boundaries": "warn",
927
+ "react-hooks/globals": "warn",
928
+ "react-hooks/immutability": "warn",
929
+ "react-hooks/incompatible-library": "warn",
930
+ "react-hooks/preserve-manual-memoization": "warn",
931
+ "react-hooks/purity": "warn",
932
+ "react-hooks/refs": "warn",
933
+ "react-hooks/set-state-in-effect": "warn",
934
+ "react-hooks/set-state-in-render": "warn",
935
+ /**
936
+ * overlaps with react/no-unstable-nested-components
937
+ */
938
+ // "react-hooks/static-components": "warn",
939
+ "react-hooks/unsupported-syntax": "warn",
940
+ "react-hooks/use-memo": "warn"
941
+ } : {},
880
942
  /**
881
943
  * Require an explicit type when using button elements.
882
944
  *
@@ -897,12 +959,6 @@ var reactRules = (functionStyle, typescript) => {
897
959
  unnamedComponents: functionStyle === "arrow" ? "arrow-function" : "function-expression"
898
960
  }
899
961
  ],
900
- /**
901
- * Require destructuring and symmetric naming of `useState` hook value and setter variables.
902
- *
903
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md
904
- */
905
- "react/hook-use-state": "warn",
906
962
  /**
907
963
  * Require consistent boolean attributes notation in JSX.
908
964
  *
@@ -993,7 +1049,12 @@ var reactRules = (functionStyle, typescript) => {
993
1049
  };
994
1050
 
995
1051
  // src/eslint/react/config.ts
996
- var reactEslintConfig = (functionStyle, typescript, customRules) => {
1052
+ var reactEslintConfig = ({
1053
+ customRules,
1054
+ functionStyle,
1055
+ reactCompiler,
1056
+ typescript
1057
+ }) => {
997
1058
  return {
998
1059
  languageOptions: {
999
1060
  globals: {
@@ -1011,7 +1072,7 @@ var reactEslintConfig = (functionStyle, typescript, customRules) => {
1011
1072
  "react-hooks": pluginReactHooks
1012
1073
  },
1013
1074
  rules: {
1014
- ...reactRules(functionStyle, typescript),
1075
+ ...reactRules({ functionStyle, reactCompiler, typescript }),
1015
1076
  ...customRules ?? {}
1016
1077
  },
1017
1078
  settings: {
@@ -1036,7 +1097,7 @@ var storybookConfig = (customRules) => [
1036
1097
  },
1037
1098
  rules: {
1038
1099
  // Default Storybook rules
1039
- "import/no-anonymous-default-export": "off",
1100
+ "import-x/no-anonymous-default-export": "off",
1040
1101
  "react-hooks/rules-of-hooks": "off",
1041
1102
  "storybook/await-interactions": "warn",
1042
1103
  "storybook/context-in-play-function": "warn",
@@ -1496,6 +1557,7 @@ var eslintConfig = ({
1496
1557
  ignores = [],
1497
1558
  importPlugin = true,
1498
1559
  jsdoc: jsdoc2 = { requireJsdoc: false },
1560
+ query = false,
1499
1561
  react: react2 = false,
1500
1562
  rules: rules2,
1501
1563
  sorting = true,
@@ -1541,10 +1603,11 @@ var eslintConfig = ({
1541
1603
  );
1542
1604
  }
1543
1605
  if (react2) {
1606
+ const reactOptions = isObject(react2) ? react2 : {};
1544
1607
  const shouldUseReactRefresh = (
1545
1608
  // Explicit setting takes precedence
1546
- isObject(react2) && react2.reactRefresh === true || // Framework-based default (vite/none use reactRefresh by default)
1547
- isObject(react2) && (react2.framework === "vite" || react2.framework === "none") && react2.reactRefresh !== false
1609
+ reactOptions.reactRefresh === true || // Framework-based default (vite/none use reactRefresh by default)
1610
+ (reactOptions.framework === "vite" || reactOptions.framework === "none") && reactOptions.reactRefresh !== false
1548
1611
  );
1549
1612
  if (shouldUseReactRefresh) {
1550
1613
  configs.push(
@@ -1552,16 +1615,20 @@ var eslintConfig = ({
1552
1615
  );
1553
1616
  }
1554
1617
  configs.push(
1555
- reactEslintConfig(
1618
+ reactEslintConfig({
1619
+ customRules: categorizedRules[configNames.react],
1556
1620
  functionStyle,
1557
- Boolean(typescript),
1558
- categorizedRules[configNames.react]
1559
- )
1621
+ reactCompiler: reactOptions.reactCompiler ?? true,
1622
+ typescript: Boolean(typescript)
1623
+ })
1560
1624
  );
1561
1625
  if (usingNextjs) {
1562
1626
  configs.push(nextjsConfig(categorizedRules[configNames.nextjs]));
1563
1627
  }
1564
1628
  }
1629
+ if (query) {
1630
+ configs.push(queryConfig(categorizedRules[configNames.query]));
1631
+ }
1565
1632
  if (testing !== false) {
1566
1633
  const mergedTestingConfig = isObject(testing) ? { ...defaultTestingConfig, ...testing } : defaultTestingConfig;
1567
1634
  const { filenamePattern, files, formattingRules, framework, itOrTest } = mergedTestingConfig;
@@ -1605,75 +1672,6 @@ var eslintConfig = ({
1605
1672
  return configs;
1606
1673
  };
1607
1674
 
1608
- // src/prettier/patch-tailwind-plugin.ts
1609
- import * as fs from "fs";
1610
- import * as path from "path";
1611
- var DECLARE_BLOCK = `declare module 'prettier' {
1612
- interface RequiredOptions extends PluginOptions {
1613
- }
1614
- interface ParserOptions extends PluginOptions {
1615
- }
1616
- }`;
1617
- var patchTailwindPlugin = () => {
1618
- try {
1619
- console.info(
1620
- "js-style-kit: Patching prettier-plugin-tailwindcss declaration file..."
1621
- );
1622
- let pluginPath;
1623
- const rootPath = path.join(
1624
- "node_modules",
1625
- "prettier-plugin-tailwindcss",
1626
- "dist",
1627
- "index.d.ts"
1628
- );
1629
- const packagePath = path.join(
1630
- process.cwd(),
1631
- "node_modules",
1632
- "prettier-plugin-tailwindcss",
1633
- "dist",
1634
- "index.d.ts"
1635
- );
1636
- if (fs.existsSync(rootPath)) {
1637
- pluginPath = rootPath;
1638
- } else if (fs.existsSync(packagePath)) {
1639
- pluginPath = packagePath;
1640
- } else {
1641
- console.warn(
1642
- "js-style-kit: prettier-plugin-tailwindcss not found, skipping patch"
1643
- );
1644
- return false;
1645
- }
1646
- console.info(`js-style-kit: Found plugin at ${pluginPath}`);
1647
- const backupPath = `${pluginPath}.backup`;
1648
- if (!fs.existsSync(backupPath)) {
1649
- fs.writeFileSync(backupPath, fs.readFileSync(pluginPath, "utf8"));
1650
- console.info("js-style-kit: Created backup of original declaration file");
1651
- }
1652
- const content = fs.readFileSync(pluginPath, "utf8");
1653
- if (!content.includes(DECLARE_BLOCK)) {
1654
- console.info(
1655
- "js-style-kit: No patching needed, declaration block not found or already patched"
1656
- );
1657
- return true;
1658
- }
1659
- const patchedContent = content.replace(
1660
- DECLARE_BLOCK,
1661
- "// Removed unsafe declare module statement"
1662
- );
1663
- fs.writeFileSync(pluginPath, patchedContent);
1664
- console.info(
1665
- "js-style-kit: Successfully patched prettier-plugin-tailwindcss declaration file"
1666
- );
1667
- return true;
1668
- } catch (error) {
1669
- console.error(
1670
- "js-style-kit: Error patching prettier-plugin-tailwindcss:",
1671
- error
1672
- );
1673
- return false;
1674
- }
1675
- };
1676
-
1677
1675
  // src/prettier/index.ts
1678
1676
  var prettierConfig = (options = {}) => {
1679
1677
  const {
@@ -1724,7 +1722,6 @@ var prettierConfig = (options = {}) => {
1724
1722
  } else {
1725
1723
  config.tailwindFunctions = defaultTailwindFunctions;
1726
1724
  }
1727
- patchTailwindPlugin();
1728
1725
  }
1729
1726
  config.plugins = plugins;
1730
1727
  return config;