eslint-plugin-hyoban 0.12.2 → 0.13.2

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.d.mts CHANGED
@@ -32,10 +32,10 @@ declare const _default: {
32
32
  'i18n-flat-key': RuleModule<[]>;
33
33
  'jsonc-inline-spacing': RuleModule<[]>;
34
34
  'jsx-attribute-spacing': RuleModule<[]>;
35
- 'markdown-consistent-table-width': _eslint_markdown.MarkdownRuleDefinition<{
35
+ 'md-consistent-table-width': _eslint_markdown.MarkdownRuleDefinition<{
36
36
  MessageIds: "formatCell";
37
37
  }>;
38
- 'markdown-paragraph-wrapping': _eslint_markdown.MarkdownRuleDefinition<{
38
+ 'md-one-sentence-per-line': _eslint_markdown.MarkdownRuleDefinition<{
39
39
  MessageIds: "wrapParagraph";
40
40
  }>;
41
41
  'no-dependency-version-prefix': RuleModule<Options>;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import stringWidth from 'fast-string-width';
2
2
 
3
- var version = "0.12.2";
3
+ var version = "0.13.2";
4
4
 
5
5
  const hasDocs = new Set([
6
6
  'prefer-tailwind-icons'
@@ -449,7 +449,7 @@ const rule$4 = {
449
449
  type: 'layout',
450
450
  docs: {
451
451
  description: 'Format GFM markdown tables to aligned columns',
452
- url: 'https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/markdown-consistent-table-width.test.ts'
452
+ url: 'https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/md-consistent-table-width.test.ts'
453
453
  },
454
454
  fixable: 'whitespace',
455
455
  schema: [],
@@ -572,12 +572,24 @@ const rule$4 = {
572
572
  }
573
573
  };
574
574
 
575
+ function lastNonWhitespaceChar(segment, segmentStart) {
576
+ for(let i = segment.length - 1; i >= 0; i--){
577
+ const char = segment[i];
578
+ if (char && !/\s/.test(char)) {
579
+ return {
580
+ char,
581
+ index: segmentStart + i
582
+ };
583
+ }
584
+ }
585
+ return null;
586
+ }
575
587
  const rule$3 = {
576
588
  meta: {
577
589
  type: 'layout',
578
590
  docs: {
579
- description: 'Wrap markdown paragraphs by sentence-ending punctuation',
580
- url: 'https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/markdown-paragraph-wrapping.test.ts'
591
+ description: 'Wrap markdown paragraphs so each sentence is on its own line',
592
+ url: 'https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/md-one-sentence-per-line.test.ts'
581
593
  },
582
594
  fixable: 'whitespace',
583
595
  schema: [],
@@ -592,37 +604,45 @@ const rule$3 = {
592
604
  },
593
605
  create (context) {
594
606
  const { sourceCode } = context;
607
+ const segmenter = new Intl.Segmenter(undefined, {
608
+ granularity: 'sentence'
609
+ });
595
610
  return {
596
611
  'root > paragraph > text': function(node) {
597
612
  const range = sourceCode.getRange(node);
598
613
  const originalText = sourceCode.getText(node);
599
- const matchPattern = /(。)[\t ]*(?=[^\r\n])|(\.)[\t ]+(?=[^\r\n])/g;
600
614
  const matches = [];
601
- let match = matchPattern.exec(originalText);
602
- while(match){
603
- const matchValue = match[0] ?? '';
604
- if (matchValue.length === 0) break;
605
- const matchedChar = match[1] ?? match[2] ?? matchValue[0] ?? '';
615
+ const segments = Array.from(segmenter.segment(originalText));
616
+ for(let i = 0; i < segments.length - 1; i++){
617
+ const current = segments[i];
618
+ const next = segments[i + 1];
619
+ if (!current || !next) continue;
620
+ const lastCharInfo = lastNonWhitespaceChar(current.segment, current.index);
621
+ if (!lastCharInfo) continue;
622
+ const boundaryStart = lastCharInfo.index + 1;
623
+ const boundaryEnd = next.index;
624
+ if (boundaryStart > boundaryEnd) continue;
625
+ const between = originalText.slice(boundaryStart, boundaryEnd);
626
+ if (between.includes('\n') || between.includes('\r')) continue;
606
627
  matches.push({
607
- index: match.index,
608
- length: matchValue.length,
609
- char: matchedChar
628
+ boundaryStart,
629
+ boundaryEnd,
630
+ locIndex: lastCharInfo.index
610
631
  });
611
- match = matchPattern.exec(originalText);
612
632
  }
613
633
  if (matches.length === 0) return;
614
634
  for (const matchItem of matches){
615
635
  context.report({
616
636
  loc: {
617
- start: sourceCode.getLocFromIndex(range[0] + matchItem.index),
618
- end: sourceCode.getLocFromIndex(range[0] + matchItem.index + 1)
637
+ start: sourceCode.getLocFromIndex(range[0] + matchItem.locIndex),
638
+ end: sourceCode.getLocFromIndex(range[0] + matchItem.locIndex + 1)
619
639
  },
620
640
  messageId: 'wrapParagraph',
621
641
  fix (fixer) {
622
642
  return fixer.replaceTextRange([
623
- range[0] + matchItem.index,
624
- range[0] + matchItem.index + matchItem.length
625
- ], `${matchItem.char}\n`);
643
+ range[0] + matchItem.boundaryStart,
644
+ range[0] + matchItem.boundaryEnd
645
+ ], '\n');
626
646
  }
627
647
  });
628
648
  }
@@ -1091,8 +1111,8 @@ var index = {
1091
1111
  'i18n-flat-key': rule$7,
1092
1112
  'jsonc-inline-spacing': rule$6,
1093
1113
  'jsx-attribute-spacing': rule$5,
1094
- 'markdown-consistent-table-width': rule$4,
1095
- 'markdown-paragraph-wrapping': rule$3,
1114
+ 'md-consistent-table-width': rule$4,
1115
+ 'md-one-sentence-per-line': rule$3,
1096
1116
  'no-dependency-version-prefix': rule$2,
1097
1117
  'prefer-early-return': rule$1,
1098
1118
  'prefer-tailwind-icons': rule
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-hyoban",
3
3
  "type": "module",
4
- "version": "0.12.2",
4
+ "version": "0.13.2",
5
5
  "description": "Hyoban extended ESLint rules.",
6
6
  "author": {
7
7
  "name": "hyoban",