Skip to content

Commit

Permalink
Merge pull request #73 from technote-space/release/next-v2.4.23
Browse files Browse the repository at this point in the history
release: v2.5.0
  • Loading branch information
technote-space authored Jun 22, 2022
2 parents 466a46c + 8fdcb23 commit 7217009
Show file tree
Hide file tree
Showing 26 changed files with 1,430 additions and 2,451 deletions.
43 changes: 11 additions & 32 deletions .eslintrc.json → .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"plugin:@typescript-eslint/eslint-recommended"
],
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"import"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -15,7 +16,8 @@
"env": {
"node": true,
"jest": true,
"es6": true
"es6": true,
"browser": true
},
"settings": {
"react": {
Expand Down Expand Up @@ -47,12 +49,6 @@
}
}
],
"no-magic-numbers": [
"error",
{
"ignoreArrayIndexes": true
}
],
"eqeqeq": "error",
"block-scoped-var": "error",
"complexity": [
Expand All @@ -61,7 +57,6 @@
"maximum": 20
}
],
"curly": "error",
"default-case": "error",
"dot-location": [
"error",
Expand All @@ -78,16 +73,6 @@
"after": true
}
],
"id-length": [
"error",
{
"min": 2,
"properties": "never",
"exceptions": [
"$"
]
}
],
"indent": [
"error",
2,
Expand Down Expand Up @@ -119,19 +104,13 @@
}
],
"semi": [
"error",
"always"
"error"
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "interface",
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": true
}
}
]
"sort-imports": 0,
"import/order": [2, {
"groups": ["type", "builtin", "external", "internal", "parent", "sibling", "index", "object"],
"alphabetize": { "order": "asc", "caseInsensitive": true }
}],
"@typescript-eslint/no-non-null-assertion": "off"
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.idea
/node_modules
/coverage
/build
/dist
.eslintcache
7 changes: 4 additions & 3 deletions __tests__/file.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {findMarkdownFiles} from '../src';
import { resolve } from 'path';
import { describe, expect, it, vi } from 'vitest';
import { findMarkdownFiles } from '../src';

describe('findMarkdownFiles', () => {
it('should find markdown files', () => {
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => ({}));
const mockLog = vi.spyOn(console, 'log').mockImplementation(() => ({}));
expect(findMarkdownFiles(resolve(__dirname, 'fixtures')).map(info => ({
name: info.name,
path: info.path,
Expand Down
5 changes: 3 additions & 2 deletions __tests__/params.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-magic-numbers */
import {extractParams, getStartSection, getParamsSection} from '../src/lib/params';
import {CLOSING_COMMENT, OPENING_COMMENT} from '../src';
import { describe, expect, it } from 'vitest';
import { CLOSING_COMMENT, OPENING_COMMENT } from '../src';
import { extractParams, getStartSection, getParamsSection } from '../src/lib/params';

describe('extractParams', () => {
const opening = OPENING_COMMENT.replace('\n', ' ');
Expand Down
9 changes: 5 additions & 4 deletions __tests__/transform-custom-mode.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.toc.split('\n')).toEqual(
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',
Expand Down
9 changes: 5 additions & 4 deletions __tests__/transform-footer.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.toc.split('\n')).toEqual(
['## Table of Contents',
Expand Down
9 changes: 5 additions & 4 deletions __tests__/transform-html.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.toc.split('\n')).toEqual(
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',
Expand Down
7 changes: 4 additions & 3 deletions __tests__/transform-nested-markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

describe('transform', () => {
it('\nhandle inline links and images', () => {
Expand Down
9 changes: 5 additions & 4 deletions __tests__/transform-not-transformed.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.transformed).toBe(false);
expect(headers.reason).toBe('update only');
Expand Down
13 changes: 7 additions & 6 deletions __tests__/transform-override-params.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.wrappedToc.split('\n')).toEqual(
[
Expand Down Expand Up @@ -36,7 +37,7 @@ describe('transform', () => {

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

expect(headers.wrappedToc.split('\n')).toEqual(
[
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('transform', () => {

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

expect(headers.wrappedToc.split('\n')).toEqual(
[
Expand Down
11 changes: 6 additions & 5 deletions __tests__/transform-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

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

expect(headers.toc.split('\n')).toEqual(
['## Table of Contents',
Expand Down Expand Up @@ -34,7 +35,7 @@ describe('transform', () => {

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

expect(headers.toc.split('\n')).toEqual(
['',
Expand Down
7 changes: 4 additions & 3 deletions __tests__/transform-weird-headers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';

describe('transform', () => {
it('given a file with edge-case header names', () => {
Expand Down
9 changes: 5 additions & 4 deletions __tests__/transform.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-magic-numbers */
import {transform} from '../src';
import {getLinesToToc, matchesStart, matchesEnd} from '../src/lib/transform';
import {OPENING_COMMENT, CLOSING_COMMENT} from '../src';
import { describe, expect, it } from 'vitest';
import { transform } from '../src';
import { OPENING_COMMENT, CLOSING_COMMENT } from '../src';
import { getLinesToToc, matchesStart, matchesEnd } from '../src/lib/transform';

const check = (
name: string,
Expand Down Expand Up @@ -499,7 +500,7 @@ describe('transform', () => {
'',
].join('\n');

const res = transform(md, {processAll: true});
const res = transform(md, { processAll: true });

expect(res.transformed).toBe(true);
expect(res.toc.split('\n')).toEqual(
Expand Down
7 changes: 4 additions & 3 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-magic-numbers */
import {replaceVariables} from '../src/lib/utils';
import { describe, expect, it } from 'vitest';
import { replaceVariables } from '../src/lib/utils';

describe('replaceVariables', () => {
it('should replace variables', () => {
expect(replaceVariables('', [])).toBe('');
expect(replaceVariables('abc/${test1}/${test2}/${test1}/xyz', [
{key: 'test1', replace: '1'},
{key: 'test3', replace: '3'},
{ key: 'test1', replace: '1' },
{ key: 'test3', replace: '3' },
])).toBe('abc/1/${test2}/1/xyz');
});
});
11 changes: 0 additions & 11 deletions jest.config.js

This file was deleted.

46 changes: 25 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/doctoc",
"version": "2.4.23",
"version": "2.5.0",
"description": "Generates TOC for markdown files of local git repo.",
"keywords": [
"github",
Expand Down Expand Up @@ -29,40 +29,44 @@
"url": "https://technote.space"
}
],
"main": "build/index.js",
"types": "build/index.d.ts",
"type": "module",
"exports": "./dist/index.mjs",
"main": "dist/index.mjs",
"files": [
"build"
],
"scripts": {
"build": "rm -rf ./build && tsc",
"cover": "jest --coverage",
"build": "tsc --emitDeclarationOnly && rollup -c",
"cover": "vitest run --coverage",
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
"test": "yarn lint && yarn cover",
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit"
"test": "yarn lint && yarn typecheck && yarn cover",
"typecheck": "tsc --noEmit",
"update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit"
},
"dependencies": {
"@technote-space/anchor-markdown-header": "^1.1.36",
"@textlint/markdown-to-ast": "^12.1.1",
"htmlparser2": "^7.2.0",
"htmlparser2": "^8.0.1",
"update-section": "^0.3.3"
},
"devDependencies": {
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@rollup/plugin-typescript": "^8.3.3",
"@sindresorhus/tsconfig": "^3.0.1",
"@textlint/ast-node-types": "^12.1.1",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"jest-circus": "^27.5.1",
"lint-staged": "^12.3.7",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"c8": "^7.11.3",
"eslint": "^8.18.0",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.2",
"rollup": "^2.75.7",
"typescript": "^4.7.4",
"vitest": "^0.15.2"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit 7217009

Please sign in to comment.