Skip to content

Commit

Permalink
improve lint rule by prettier and vscode editor setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiazya committed Feb 5, 2020
1 parent 3482322 commit e859c1f
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 51 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"printWidth": 120,
"bracketSpacing": true
}
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"editor.formatOnSave": false,
"editor.formatOnPaste": false,
"editor.formatOnType": false,
"editor.codeActionsOnSave": {
"source.fixAll.tslint": true
},
"tslint.exclude": ["**/dist/**", "**/node_modules/**"],
"markdownlint.config": {
"default": true,
"MD041": false
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![GitHub Action](https://github.com/kamiazya/typedoc-plugin-mermaid/workflows/Node%20CI/badge.svg)](https://github.com/kamiazya/typedoc-plugin-mermaid/actions?workflow=Node+CI) [![CodeFactor](https://www.codefactor.io/repository/github/kamiazya/typedoc-plugin-mermaid/badge)](https://www.codefactor.io/repository/github/kamiazya/typedoc-plugin-mermaid) [![npm version](https://badge.fury.io/js/typedoc-plugin-mermaid.svg)](https://badge.fury.io/js/typedoc-plugin-mermaid) [![Maintainability](https://api.codeclimate.com/v1/badges/827855fa3daba03076b4/maintainability)](https://codeclimate.com/github/kamiazya/typedoc-plugin-mermaid/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/827855fa3daba03076b4/test_coverage)](https://codeclimate.com/github/kamiazya/typedoc-plugin-mermaid/test_coverage) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkamiazya%2Ftypedoc-plugin-mermaid.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkamiazya%2Ftypedoc-plugin-mermaid?ref=badge_shield) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![typedoc-plugin-mermaid Dev Token](https://badge.devtoken.rocks/typedoc-plugin-mermaid)](https://devtoken.rocks/package/typedoc-plugin-mermaid) [![BCH compliance](https://bettercodehub.com/edge/badge/kamiazya/typedoc-plugin-mermaid?branch=master)](https://bettercodehub.com/)
[![GitHub Action](https://github.com/kamiazya/typedoc-plugin-mermaid/workflows/Node%20CI/badge.svg)](https://github.com/kamiazya/typedoc-plugin-mermaid/actions?workflow=Node+CI) [![CodeFactor](https://www.codefactor.io/repository/github/kamiazya/typedoc-plugin-mermaid/badge)](https://www.codefactor.io/repository/github/kamiazya/typedoc-plugin-mermaid) [![npm version](https://badge.fury.io/js/typedoc-plugin-mermaid.svg)](https://badge.fury.io/js/typedoc-plugin-mermaid) [![Maintainability](https://api.codeclimate.com/v1/badges/827855fa3daba03076b4/maintainability)](https://codeclimate.com/github/kamiazya/typedoc-plugin-mermaid/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/827855fa3daba03076b4/test_coverage)](https://codeclimate.com/github/kamiazya/typedoc-plugin-mermaid/test_coverage) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkamiazya%2Ftypedoc-plugin-mermaid.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkamiazya%2Ftypedoc-plugin-mermaid?ref=badge_shield) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![typedoc-plugin-mermaid Dev Token](https://badge.devtoken.rocks/typedoc-plugin-mermaid)](https://devtoken.rocks/package/typedoc-plugin-mermaid) [![BCH compliance](https://bettercodehub.com/edge/badge/kamiazya/typedoc-plugin-mermaid?branch=master)](https://bettercodehub.com/)

# typedoc-plugin-mermaid

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
"jest": "^24.3.1",
"jest-haste-map": "^24.0.0",
"jest-resolve": "^24.1.0",
"prettier": "^1.19.1",
"release-it": "^12.0.1",
"ts-jest": "^24.0.0",
"tslint": "^5.13.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.1.0",
"typedoc": "^0.16.9",
"typescript": "^3.7.5"
},
Expand Down
55 changes: 17 additions & 38 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { PageEvent } from 'typedoc/dist/lib/output/events';
*/
@Component({ name: 'mermaid' })
export class MermaidPlugin extends ConverterComponent {

/**
* 1. Load mermaid.js library.
* 2. Initialize mermaid.
Expand Down Expand Up @@ -52,27 +51,13 @@ export class MermaidPlugin extends ConverterComponent {
* get CommentTags for using `@mermaid` annotation from Context.
*/
private static mermaidTags(context: Context): CommentTag[] {
return Object
// get reflection from context
.values(context.project.reflections)

// get Comment from Reflection
.map(reflection => reflection.comment)

// filter only comment exist
.filter(this.filterComment)

// get CommentTags from Comment
.map(comment => comment.tags)

// filter only CommentTags exist
.filter(this.filterCommentTags)

// merge all CommentTags
.reduce((a, b) => a.concat(b), [])

// filter tag that paramName is 'mermaid'
.filter(this.isMermaidCommentTag);
return Object.values(context.project.reflections) // get reflection from context
.map(reflection => reflection.comment) // get Comment from Reflection
.filter(this.filterComment) // filter only comment exist
.map(comment => comment.tags) // get CommentTags from Comment
.filter(this.filterCommentTags) // filter only CommentTags exist
.reduce((a, b) => a.concat(b), []) // merge all CommentTags
.filter(this.isMermaidCommentTag); // filter tag that paramName is 'mermaid'
}

/**
Expand All @@ -98,9 +83,7 @@ export class MermaidPlugin extends ConverterComponent {
*/
public convertPageContents(contents: string): string {
if (this.BODY_CLOSING_TAG.test(contents)) {
return contents.replace(
this.BODY_CLOSING_TAG,
MermaidPlugin.customScriptsAndBodyClosingTag);
return contents.replace(this.BODY_CLOSING_TAG, MermaidPlugin.customScriptsAndBodyClosingTag);
}
return contents;
}
Expand All @@ -109,25 +92,21 @@ export class MermaidPlugin extends ConverterComponent {
* listen to event on initialization
*/
public initialize() {
this
.listenTo(this.owner, {
[Converter.EVENT_RESOLVE_BEGIN]: this.onResolveBegin,
})
.listenTo(this.application.renderer, {
[PageEvent.END]: this.onPageEnd,
});
this.listenTo(this.owner, {
[Converter.EVENT_RESOLVE_BEGIN]: this.onResolveBegin,
}).listenTo(this.application.renderer, {
[PageEvent.END]: this.onPageEnd,
});
}

/**
* Triggered when the converter begins converting a project.
*/
public onResolveBegin(context: Context) {
MermaidPlugin
.mermaidTags(context)
.forEach((tag) => {
// convert
tag.text = this.convertCommentTagText(tag.text);
});
MermaidPlugin.mermaidTags(context).forEach(tag => {
// convert
tag.text = this.convertCommentTagText(tag.text);
});
}

/**
Expand Down
26 changes: 16 additions & 10 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"rules": {
"quotemark": [true, "single"],
"no-console": [false],
"arrow-parens": false,
"object-literal-sort-keys": false
}
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"rules": {
"prettier": true,
"import-spacing": true,
"quotemark": [true, "single"],
"no-console": [false],
"arrow-parens": false,
"object-literal-sort-keys": false
},
"rulesDirectory": [
"tslint-plugin-prettier"
]
}
44 changes: 43 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,14 @@ escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"

eslint-plugin-prettier@^2.2.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.7.0.tgz#b4312dcf2c1d965379d7f9d5b5f8aaadc6a45904"
integrity sha512-CStQYJgALoQBw3FsBzH0VOVDRnJ/ZimUlpLm226U8qgqYJfPOY/CPK6wyRInMxh73HSKg5wyRwdS4BVYYHwokA==
dependencies:
fast-diff "^1.1.1"
jest-docblock "^21.0.0"

esprima@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
Expand Down Expand Up @@ -1530,6 +1538,11 @@ fast-deep-equal@^2.0.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=

fast-diff@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-glob@^3.0.3:
version "3.0.4"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.0.4.tgz#d484a41005cb6faeb399b951fd1bd70ddaebb602"
Expand Down Expand Up @@ -2440,6 +2453,11 @@ jest-diff@^24.9.0:
jest-get-type "^24.9.0"
pretty-format "^24.9.0"

jest-docblock@^21.0.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414"
integrity sha512-5IZ7sY9dBAYSV+YjQ0Ovb540Ku7AO9Z5o2Cg789xj167iQuZ2cG+z0f3Uct6WeYLbU6aQiM2pCs7sZ+4dotydw==

jest-docblock@^24.3.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-24.9.0.tgz#7970201802ba560e1c4092cc25cbedf5af5a8ce2"
Expand Down Expand Up @@ -2903,6 +2921,11 @@ levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lines-and-columns@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=

load-json-file@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
Expand Down Expand Up @@ -3662,6 +3685,11 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=

prettier@^1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

pretty-format@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
Expand Down Expand Up @@ -4529,11 +4557,25 @@ ts-jest@^24.0.0:
semver "^5.5"
yargs-parser "10.x"

tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

tslint-config-prettier@^1.18.0:
version "1.18.0"
resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz#75f140bde947d35d8f0d238e0ebf809d64592c37"
integrity sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==

tslint-plugin-prettier@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslint-plugin-prettier/-/tslint-plugin-prettier-2.1.0.tgz#e2522d273cb9672d93d0e68f2514fe3c19698c3a"
integrity sha512-nMCpU+QSpXtydcWXeZF+3ljIbG/K8SHVZwB7K/MtuoQQFXxXN6watqTSBpVXCInuPFvmjiWkhxeMoUW4N0zgSg==
dependencies:
eslint-plugin-prettier "^2.2.0"
lines-and-columns "^1.1.6"
tslib "^1.7.1"

tslint@^5.13.1:
version "5.20.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.0.tgz#fac93bfa79568a5a24e7be9cdde5e02b02d00ec1"
Expand Down

0 comments on commit e859c1f

Please sign in to comment.