heading-case 0.1.0 → 0.1.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/README.md CHANGED
@@ -38,12 +38,18 @@ Install:
38
38
  npm add heading-case -D
39
39
  ```
40
40
 
41
- Format all markdown and MDX files in the current directory:
41
+ Check all markdown and MDX files in the current directory:
42
42
 
43
43
  ```bash
44
44
  npx heading-case
45
45
  ```
46
46
 
47
+ Check and write the formatted content to the file:
48
+
49
+ ```bash
50
+ npx heading-case --write
51
+ ```
52
+
47
53
  ## License
48
54
 
49
55
  [MIT](./LICENSE).
package/dist/index.js CHANGED
@@ -2965,6 +2965,7 @@ const isTerm = (word, line)=>dict.some((term)=>{
2965
2965
  if (term.includes(` ${word}`) || term.includes(`${word} `)) return line.includes(term);
2966
2966
  return term === word;
2967
2967
  });
2968
+ const shouldWrite = process.argv.includes('--write');
2968
2969
  const formatLine = (originalLine)=>{
2969
2970
  let line = originalLine;
2970
2971
  const words = line.trim().split(/\s+/);
@@ -2980,20 +2981,28 @@ const formatLine = (originalLine)=>{
2980
2981
  }
2981
2982
  return line;
2982
2983
  };
2983
- function formatContent(content) {
2984
+ function formatContent(content, filePath) {
2984
2985
  const lines = content.split('\n');
2985
2986
  return lines.map((originalLine)=>{
2986
- if (isTitleLine(originalLine)) return formatLine(originalLine);
2987
+ if (isTitleLine(originalLine)) {
2988
+ const formattedLine = formatLine(originalLine);
2989
+ if (!shouldWrite && formattedLine !== originalLine) {
2990
+ logger.error(`Unexpected heading case in ${picocolors_default().dim(filePath)}`);
2991
+ logger.log(` Current: ${picocolors_default().cyan(originalLine)}`);
2992
+ logger.log(` Expected: ${picocolors_default().cyan(formattedLine)}\n`);
2993
+ }
2994
+ return formattedLine;
2995
+ }
2987
2996
  return originalLine;
2988
2997
  }).join('\n');
2989
2998
  }
2990
2999
  async function formatFile(filePath) {
2991
3000
  const content = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(filePath, 'utf-8');
2992
- const formatted = formatContent(content);
3001
+ const formatted = formatContent(content, filePath);
2993
3002
  const isChanged = formatted !== content;
2994
- if (isChanged) {
3003
+ if (isChanged && shouldWrite) {
2995
3004
  await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.writeFile(filePath, formatted);
2996
- logger.success(`formatted: ${picocolors_default().dim(filePath)}`);
3005
+ logger.success(`[heading-case] formatted: ${picocolors_default().dim(filePath)}`);
2997
3006
  }
2998
3007
  return isChanged;
2999
3008
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heading-case",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "repository": "https://github.com/rspack-contrib/heading-case",
5
5
  "license": "MIT",
6
6
  "type": "module",