Skip to content

Commit 0f70d72

Browse files
chore: tweaks
1 parent 1a67a91 commit 0f70d72

18 files changed

+65
-65
lines changed

__tests__/file.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it, vi } from 'vitest';
3-
import {resolve} from 'path';
4-
import {findMarkdownFiles} from '../src';
3+
import { resolve } from 'path';
4+
import { findMarkdownFiles } from '../src';
55

66
describe('findMarkdownFiles', () => {
77
it('should find markdown files', () => {

__tests__/params.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {extractParams, getStartSection, getParamsSection} from '../src/lib/params';
4-
import {CLOSING_COMMENT, OPENING_COMMENT} from '../src';
3+
import { extractParams, getStartSection, getParamsSection } from '../src/lib/params';
4+
import { CLOSING_COMMENT, OPENING_COMMENT } from '../src';
55

66
describe('extractParams', () => {
77
const opening = OPENING_COMMENT.replace('\n', ' ');

__tests__/transform-custom-mode.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('run in html mode', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
10-
const headers = transform(content, {mode: 'github.com', isCustomMode: true});
10+
const headers = transform(content, { mode: 'github.com', isCustomMode: true });
1111

1212
expect(headers.toc.split('\n')).toEqual(
1313
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',

__tests__/transform-footer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('add footer', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
10-
const headers = transform(content, {title: '## Table of Contents', footer: '*generated with [TOC Generator](https://github.com/technote-space/toc-generator)*'});
10+
const headers = transform(content, { title: '## Table of Contents', footer: '*generated with [TOC Generator](https://github.com/technote-space/toc-generator)*' });
1111

1212
expect(headers.toc.split('\n')).toEqual(
1313
['## Table of Contents',

__tests__/transform-html.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('given a file that includes html with header tags and maxHeaderLevel 8', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
10-
const headers = transform(content, {mode: 'github.com', maxHeaderLevel: 8});
10+
const headers = transform(content, { mode: 'github.com', maxHeaderLevel: 8 });
1111

1212
expect(headers.toc.split('\n')).toEqual(
1313
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',

__tests__/transform-nested-markdown.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('\nhandle inline links and images', () => {

__tests__/transform-not-transformed.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('update only', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-update-only.md'), 'utf8');
10-
const headers = transform(content, {updateOnly: true});
10+
const headers = transform(content, { updateOnly: true });
1111

1212
expect(headers.transformed).toBe(false);
1313
expect(headers.reason).toBe('update only');

__tests__/transform-override-params.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('override params (empty toc)', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params1.md'), 'utf8');
10-
const headers = transform(content, {isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*'});
10+
const headers = transform(content, { isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*' });
1111

1212
expect(headers.wrappedToc.split('\n')).toEqual(
1313
[
@@ -37,7 +37,7 @@ describe('transform', () => {
3737

3838
it('override params (not empty toc)', () => {
3939
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params2.md'), 'utf8');
40-
const headers = transform(content, {isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*', footer: 'footer'});
40+
const headers = transform(content, { isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*', footer: 'footer' });
4141

4242
expect(headers.wrappedToc.split('\n')).toEqual(
4343
[
@@ -70,7 +70,7 @@ describe('transform', () => {
7070

7171
it('not override params', () => {
7272
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params1.md'), 'utf8');
73-
const headers = transform(content, {isFolding: true, title: 'Test title'});
73+
const headers = transform(content, { isFolding: true, title: 'Test title' });
7474

7575
expect(headers.wrappedToc.split('\n')).toEqual(
7676
[

__tests__/transform-title.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('overwrite existing title', () => {
99
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
10-
const headers = transform(content, {title: '## Table of Contents'});
10+
const headers = transform(content, { title: '## Table of Contents' });
1111

1212
expect(headers.toc.split('\n')).toEqual(
1313
['## Table of Contents',
@@ -35,7 +35,7 @@ describe('transform', () => {
3535

3636
it('clobber existing title', () => {
3737
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
38-
const headers = transform(content, {isNotitle: true});
38+
const headers = transform(content, { isNotitle: true });
3939

4040
expect(headers.toc.split('\n')).toEqual(
4141
['',

__tests__/transform-weird-headers.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {resolve} from 'path';
4-
import {readFileSync} from 'fs';
5-
import {transform} from '../src';
3+
import { resolve } from 'path';
4+
import { readFileSync } from 'fs';
5+
import { transform } from '../src';
66

77
describe('transform', () => {
88
it('given a file with edge-case header names', () => {

__tests__/transform.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {transform} from '../src';
4-
import {getLinesToToc, matchesStart, matchesEnd} from '../src/lib/transform';
5-
import {OPENING_COMMENT, CLOSING_COMMENT} from '../src';
3+
import { transform } from '../src';
4+
import { getLinesToToc, matchesStart, matchesEnd } from '../src/lib/transform';
5+
import { OPENING_COMMENT, CLOSING_COMMENT } from '../src';
66

77
const check = (
88
name: string,
@@ -500,7 +500,7 @@ describe('transform', () => {
500500
'',
501501
].join('\n');
502502

503-
const res = transform(md, {processAll: true});
503+
const res = transform(md, { processAll: true });
504504

505505
expect(res.transformed).toBe(true);
506506
expect(res.toc.split('\n')).toEqual(

__tests__/utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-magic-numbers */
22
import { describe, expect, it } from 'vitest';
3-
import {replaceVariables} from '../src/lib/utils';
3+
import { replaceVariables } from '../src/lib/utils';
44

55
describe('replaceVariables', () => {
66
it('should replace variables', () => {
77
expect(replaceVariables('', [])).toBe('');
88
expect(replaceVariables('abc/${test1}/${test2}/${test1}/xyz', [
9-
{key: 'test1', replace: '1'},
10-
{key: 'test3', replace: '3'},
9+
{ key: 'test1', replace: '1' },
10+
{ key: 'test3', replace: '3' },
1111
])).toBe('abc/1/${test2}/1/xyz');
1212
});
1313
});

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export {findMarkdownFiles} from './lib/file';
2-
export {transform} from './lib/transform';
1+
export { findMarkdownFiles } from './lib/file';
2+
export { transform } from './lib/transform';
33
export {
44
OPENING_COMMENT,
55
CLOSING_COMMENT,

src/lib/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import {FileInfo, FileAndDirs} from '../types';
4-
import {MARKDOWN_EXTENSIONS, IGNORED_DIRS} from '..';
3+
import { FileInfo, FileAndDirs } from '../types';
4+
import { MARKDOWN_EXTENSIONS, IGNORED_DIRS } from '..';
55

66
const separateFilesAndDirs = (fileInfos: Array<FileInfo>): FileAndDirs => ({
77
directories: fileInfos.filter(info => info.stat.isDirectory() && !IGNORED_DIRS.includes(info.name)),

src/lib/get-html-headers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as htmlparser from 'htmlparser2';
22
import * as md from '@textlint/markdown-to-ast';
3-
import {HeaderData, Header} from '../types';
3+
import { HeaderData, Header } from '../types';
44

55
const addLinenos = (lines: Array<string>, headers: Array<HeaderData>): Array<Omit<Header, 'rank'> & HeaderData> => {
66
let current = 0;
@@ -73,11 +73,11 @@ export const getHtmlHeaders = (lines: Array<string>, maxHeaderLevel: number): Ar
7373
// eslint-disable-next-line no-magic-numbers
7474
if (grabbing[grabbing.length - 1] === name) {
7575
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76-
headers.push({text: [...text], tag: grabbing.pop()!});
76+
headers.push({ text: [...text], tag: grabbing.pop()! });
7777
text.length = 0;
7878
}
7979
},
80-
}, {decodeEntities: true});
80+
}, { decodeEntities: true });
8181

8282
parser.write(source);
8383
parser.end();

src/lib/params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {SectionInfo, TransformOptions} from '../types';
1+
import { SectionInfo, TransformOptions } from '../types';
22

33
const getBoolValue = (input: string): boolean => !['false', '0', '', 'no', 'n'].includes(input.trim().toLowerCase());
44
const converter = {
@@ -43,7 +43,7 @@ export const extractParams = (section: string): TransformOptions => Object.assig
4343
).filter(
4444
(items): items is Array<string> => items !== null && items[1] in converter,
4545
).map(
46-
items => ({[items[1]]: converter[items[1]](items[2])}),
46+
items => ({ [items[1]]: converter[items[1]](items[2]) }),
4747
) ?? []));
4848

4949
export const getParamsSection = (options: TransformOptions): string => {

src/lib/transform.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type {TxtNode} from '@textlint/ast-node-types';
2-
import type {TransformOptions, Header, HeaderWithRepetition, HeaderWithAnchor, SectionInfo, TransformResult} from '../types';
3-
import {anchor, getUrlHash} from '@technote-space/anchor-markdown-header';
1+
import type { TxtNode } from '@textlint/ast-node-types';
2+
import type { TransformOptions, Header, HeaderWithRepetition, HeaderWithAnchor, SectionInfo, TransformResult } from '../types';
3+
import { anchor, getUrlHash } from '@technote-space/anchor-markdown-header';
44
import updateSection from 'update-section';
55
import * as md from '@textlint/markdown-to-ast';
6-
import {getHtmlHeaders} from './get-html-headers';
7-
import {getStartSection, extractParams, getParamsSection} from './params';
8-
import {replaceVariables} from './utils';
6+
import { getHtmlHeaders } from './get-html-headers';
7+
import { getStartSection, extractParams, getParamsSection } from './params';
8+
import { replaceVariables } from './utils';
99
import {
1010
OPENING_COMMENT,
1111
CLOSING_COMMENT,
@@ -141,8 +141,8 @@ const getHtmlHeaderContents = (headers: Array<HeaderWithAnchor>, lowestRank: num
141141

142142
const getHeaderItemHtml = (header: HeaderWithAnchor, itemTemplate: string | undefined): string => {
143143
return replaceVariables(itemTemplate ?? DEFAULT_ITEM_TEMPLATE, [
144-
{key: 'LINK', replace: `#${header.hash}`},
145-
{key: 'TEXT', replace: header.name},
144+
{ key: 'LINK', replace: `#${header.hash}` },
145+
{ key: 'TEXT', replace: header.name },
146146
]);
147147
};
148148

@@ -208,10 +208,10 @@ export const transform = (
208208
itemTemplate,
209209
separator,
210210
footer,
211-
} = {...options, ...extractedOptions};
211+
} = { ...options, ...extractedOptions };
212212

213213
if (!info.hasStart && updateOnly) {
214-
return getResult({transformed: false, reason: 'update only'});
214+
return getResult({ transformed: false, reason: 'update only' });
215215
}
216216

217217
const _mode = mode || 'github.com';
@@ -237,7 +237,7 @@ export const transform = (
237237
const toc = buildToc(isCustomMode, inferredTitle, linkedHeaders, lowestRank, customTemplate, itemTemplate, separator, indentation, _entryPrefix, footer);
238238
const wrappedToc = (openingComment ?? OPENING_COMMENT) + getParamsSection(extractedOptions) + '\n' + wrapToc(toc, inferredTitle, isFolding) + '\n' + (closingComment ?? CLOSING_COMMENT);
239239
if (currentToc === wrappedToc) {
240-
return getResult({transformed: false, reason: 'not updated'});
240+
return getResult({ transformed: false, reason: 'not updated' });
241241
}
242242

243243
return getResult({

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Stats} from 'fs';
1+
import { Stats } from 'fs';
22

33
export type TransformOptions = Partial<{
44
mode: string;

0 commit comments

Comments
 (0)