@kitschpatrol/remark-config 2.2.1 → 3.0.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/init/.remarkrc.js CHANGED
@@ -1,10 +1,9 @@
1
- import sharedConfig from '@kitschpatrol/remark-config';
1
+ import sharedConfig, { overrideRules } from '@kitschpatrol/remark-config';
2
2
 
3
3
  const localConfig = {
4
- // Overrides
5
- };
6
-
7
- export default {
8
4
  ...sharedConfig,
9
- ...localConfig,
5
+ // Overrides are a special case, working as below (set `false` as the second element to disable):
6
+ // plugins: overrideRules(sharedConfig.plugins, [['remark-lint-first-heading-level', 2]])
10
7
  };
8
+
9
+ export default localConfig;
package/main.js CHANGED
@@ -8,7 +8,6 @@ import remarkLintCodeBlockStyle from 'remark-lint-code-block-style';
8
8
  import remarkLintEmphasisMarker from 'remark-lint-emphasis-marker';
9
9
  import remarkLintFencedCodeFlag from 'remark-lint-fenced-code-flag';
10
10
  import remarkLintFencedCodeMarker from 'remark-lint-fenced-code-marker';
11
- import remarkLintFileExtension from 'remark-lint-file-extension';
12
11
  import remarkLintFinalDefinition from 'remark-lint-final-definition';
13
12
  import remarkLintFirstHeadingLevel from 'remark-lint-first-heading-level';
14
13
  import remarkLintHeadingIncrement from 'remark-lint-heading-increment';
@@ -23,7 +22,6 @@ import remarkLintNoEmptyUrl from 'remark-lint-no-empty-url';
23
22
  import remarkLintNoFileNameArticles from 'remark-lint-no-file-name-articles';
24
23
  import remarkLintNoFileNameConsecutiveDashes from 'remark-lint-no-file-name-consecutive-dashes';
25
24
  import remarkLintNoFileNameIrregularCharacters from 'remark-lint-no-file-name-irregular-characters';
26
- import remarkLintNoFileNameMixedCase from 'remark-lint-no-file-name-mixed-case';
27
25
  import remarkLintNoFileNameOuterDashes from 'remark-lint-no-file-name-outer-dashes';
28
26
  import remarkLintNoHeadingIndent from 'remark-lint-no-heading-indent';
29
27
  import remarkLintNoHeadingLikeParagraph from 'remark-lint-no-heading-like-paragraph';
@@ -50,6 +48,47 @@ import remarkLintUnorderedListMarkerStyle from 'remark-lint-unordered-list-marke
50
48
  import remarkPresetPrettier from 'remark-preset-prettier';
51
49
  import remarkValidateLinks from 'remark-validate-links';
52
50
 
51
+ /**
52
+ * Overrides specific rules in a set of plugins.
53
+ *
54
+ * This function searches through an array of plugins to find and override
55
+ * multiple plugins by their names, replacing their arguments with new ones.
56
+ *
57
+ * See this link for why we need this:
58
+ * https://github.com/remarkjs/remark-lint/issues/165
59
+ *
60
+ * @param {any[]} plugins - An array of plugins, where each plugin is either a function or an array containing a function and its arguments.
61
+ * @param {Array.<[string, any]>} rules - An array of [ruleName, newArgs] pairs, where `ruleName` is the name of the rule to override and `newArgs` are the new arguments to apply.
62
+ * @returns {any[]} The modified array of plugins with the overridden rules.
63
+ */
64
+ export function overrideRules(plugins, rules) {
65
+ for (let [ruleName, newArguments] of rules) {
66
+ // Internally, function names are different from the package names
67
+ ruleName = ruleName.replace(/^remark-lint-/, 'remark-lint:');
68
+
69
+ let ruleFunction;
70
+ const index = plugins.findIndex((plugin) => {
71
+ if (Array.isArray(plugin)) {
72
+ if (plugin[0]?.name === ruleName) {
73
+ ruleFunction = plugin[0];
74
+ return true;
75
+ }
76
+ } else if (plugin.name === ruleName) {
77
+ ruleFunction = plugin;
78
+ return true;
79
+ }
80
+
81
+ return false;
82
+ });
83
+
84
+ if (index !== -1) {
85
+ plugins.splice(index, 1, [ruleFunction, newArguments]);
86
+ }
87
+ }
88
+
89
+ return plugins;
90
+ }
91
+
53
92
  export default {
54
93
  plugins: [
55
94
  remarkLint,
@@ -62,7 +101,8 @@ export default {
62
101
  [remarkLintEmphasisMarker, '*'],
63
102
  [remarkLintFencedCodeFlag, { allowEmpty: false }],
64
103
  [remarkLintFencedCodeMarker, '`'],
65
- [remarkLintFileExtension, 'md'],
104
+ // Crashes with "Cannot use 'in' operator to search for 'start' in undefined"
105
+ // [remarkLintFileExtension, 'md'],
66
106
  remarkLintFinalDefinition,
67
107
  remarkLintFirstHeadingLevel,
68
108
  remarkLintHeadingIncrement,
@@ -79,7 +119,8 @@ export default {
79
119
  remarkLintNoFileNameArticles,
80
120
  remarkLintNoFileNameConsecutiveDashes,
81
121
  remarkLintNoFileNameIrregularCharacters,
82
- remarkLintNoFileNameMixedCase,
122
+ // Crashes with "Cannot use 'in' operator to search for 'start' in undefined"
123
+ // RemarkLintNoFileNameMixedCase,
83
124
  remarkLintNoFileNameOuterDashes,
84
125
  remarkLintNoHeadingIndent,
85
126
  remarkLintNoHeadingLikeParagraph,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/remark-config",
3
- "version": "2.2.1",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "description": "Linting for markdown and MDX files, managed via ESLint.",
6
6
  "repository": {
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "main": "main.js",
29
29
  "files": [
30
- "bin",
31
- "init"
30
+ "bin/*",
31
+ "init/*"
32
32
  ],
33
33
  "dependencies": {
34
34
  "@pinojs/json-colorizer": "^4.0.0",
package/readme.md CHANGED
@@ -13,7 +13,7 @@ To use just this Remark config in isolation:
13
13
  1. Install the `.npmrc` in your project root. This is required for correct PNPM behavior:
14
14
 
15
15
  ```sh
16
- pnpm dlx @kitschpatrol/npm-config
16
+ pnpm dlx @kitschpatrol/repo-config
17
17
  ```
18
18
 
19
19
  2. Add the package: