Skip to content

Commit cd72a0f

Browse files
committed
eslint-plugin-prettier
1 parent 18fb4d8 commit cd72a0f

36 files changed

+189
-195
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"lint-staged": {
1818
"*.{js,ts}": [
19-
"eslint --fix",
19+
"lerna run lint:fix",
2020
"git add"
2121
]
2222
},

packages/example/webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ module.exports = {
7777
// sourceDir: 'abc'
7878
// TODO
7979
contentCssClass: 'markdown-body',
80-
// markdown: {
81-
// lineNumbers: true,
82-
// }
80+
markdown: {
81+
lineNumbers: true,
82+
}
8383
}
8484
}
8585
]

packages/vue-markdown-loader/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module.exports = {
66
'jest/globals': true,
77
},
88
'extends': [
9-
'standard',
9+
"plugin:prettier/recommended",
10+
"prettier/standard",
1011
'plugin:jest/recommended',
1112
],
1213
'parser': '@typescript-eslint/parser',
@@ -16,6 +17,7 @@ module.exports = {
1617
},
1718
'plugins': [
1819
'jest',
20+
'prettier',
1921
'@typescript-eslint',
2022
],
2123
'rules': {

packages/vue-markdown-loader/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"release": "node build/release.js",
2323
"test": "jest --config=jest.config.js",
2424
"lint": "eslint --ext .js,.ts src",
25-
"lint:fix": "prettier --write \"src/**/*.ts\" && eslint --ext .js,.ts src --fix"
25+
"lint:fix": "yarn run lint --fix"
2626
},
2727
"dependencies": {
2828
"chalk": "^2.4.2",
@@ -51,12 +51,14 @@
5151
"@typescript-eslint/parser": "^1.3.0",
5252
"babel-loader": "^8.0.5",
5353
"eslint": "^5.16.0",
54+
"eslint-config-prettier": "^4.2.0",
5455
"eslint-config-standard": "^12.0.0",
5556
"eslint-friendly-formatter": "^4.0.1",
5657
"eslint-loader": "^2.1.2",
5758
"eslint-plugin-import": "^2.9.0",
5859
"eslint-plugin-jest": "^22.5.0",
5960
"eslint-plugin-node": "^8.0.0",
61+
"eslint-plugin-prettier": "^3.0.1",
6062
"eslint-plugin-promise": "^4.0.0",
6163
"eslint-plugin-standard": "^4.0.0",
6264
"execa": "^1.0.0",

packages/vue-markdown-loader/src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parseFrontmatter, inferTitle, extractHeaders } from './utils'
77

88
const devCache = new LRU({ max: 1000 })
99

10-
export default function (src) {
10+
export default function(src) {
1111
const isProd = process.env.NODE_ENV === 'production'
1212
const isServer = this.target === 'node'
1313
const options = getOptions(this) || {}
@@ -32,11 +32,12 @@ export default function (src) {
3232

3333
// diff frontmatter and title, since they are not going to be part of the
3434
// returned component, changes in frontmatter do not trigger proper updates
35-
if (cachedData && (
36-
cachedData.inferredTitle !== inferredTitle ||
37-
JSON.stringify(cachedData.frontmatterData) !== JSON.stringify(data) ||
38-
headersChanged(cachedData.headers, headers)
39-
)) {
35+
if (
36+
cachedData &&
37+
(cachedData.inferredTitle !== inferredTitle ||
38+
JSON.stringify(cachedData.frontmatterData) !== JSON.stringify(data) ||
39+
headersChanged(cachedData.headers, headers))
40+
) {
4041
// frontmatter changed... need to do a full reload
4142
frontmatterEmitter.emit('update', file)
4243
}
@@ -58,7 +59,7 @@ export default function (src) {
5859
return `<template>\n` + `<div class="content ${contentCssClass}">${html}</div>\n` + `</template>\n`
5960
}
6061

61-
function headersChanged (a: any[], b: any[]): boolean {
62+
function headersChanged(a: any[], b: any[]): boolean {
6263
if (a.length !== b.length) {
6364
return true
6465
}

packages/vue-markdown-loader/src/markdown/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default (markdown: any = {}) => {
6262
// .use(tocPlugin, [toc])
6363
// .end()
6464

65-
if (!lineNumbers) {
65+
if (lineNumbers) {
6666
config
6767
.plugin(PLUGINS.LINE_NUMBERS)
6868
.use(lineNumbersPlugin)
@@ -97,7 +97,7 @@ export default (markdown: any = {}) => {
9797
return md
9898
}
9999

100-
export function dataReturnable (md) {
100+
export function dataReturnable(md) {
101101
// override render to allow custom plugins return data
102102
const render = md.render
103103
md.render = (...args) => {
@@ -113,30 +113,28 @@ export function dataReturnable (md) {
113113
}
114114
}
115115

116-
function toDataBlockString (ob) {
116+
function toDataBlockString(ob) {
117117
if (Object.keys(ob).length === 0) {
118118
return ''
119119
}
120120
return `<data>${JSON.stringify(ob)}</data>`
121121
}
122122

123-
export function isRequiredPlugin (plugin) {
123+
export function isRequiredPlugin(plugin) {
124124
return REQUIRED_PLUGINS.includes(plugin)
125125
}
126126

127-
export function removePlugin (config, plugin) {
127+
export function removePlugin(config, plugin) {
128128
logger.debug(`Built-in markdown-it plugin ${chalk.green(plugin)} was removed.`)
129129
config.plugins.delete(plugin)
130130
}
131131

132-
export function removeAllBuiltInPlugins (config) {
132+
export function removeAllBuiltInPlugins(config) {
133133
Object.keys(PLUGINS).forEach(key => {
134134
if (!isRequiredPlugin(PLUGINS[key])) {
135135
removePlugin(config, PLUGINS[key])
136136
}
137137
})
138138
}
139139

140-
export {
141-
PLUGINS,
142-
}
140+
export { PLUGINS }

packages/vue-markdown-loader/src/markdown/lib/containers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import container from 'markdown-it-container'
22

3-
function createContainer (name: string, defaultTitle: string) {
3+
function createContainer(name: string, defaultTitle: string) {
44
return [
55
container,
66
name,
77
{
8-
render (tokens, idx) {
8+
render(tokens, idx) {
99
const token = tokens[idx]
10-
const info = token.info
11-
.trim()
12-
.slice(name.length)
13-
.trim() || defaultTitle
10+
const info =
11+
token.info
12+
.trim()
13+
.slice(name.length)
14+
.trim() || defaultTitle
1415
if (token.nesting === 1) {
1516
return `<div class="${name} custom-block"><p class="custom-block-title">${info}</p>\n`
1617
} else {

packages/vue-markdown-loader/src/markdown/lib/highlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import loadLanguages from 'prismjs/components/index'
55
// required to make embedded highlighting work...
66
loadLanguages(['markup', 'css', 'javascript'])
77

8-
function wrap (code, lang) {
8+
function wrap(code, lang) {
99
if (lang === 'text') {
1010
// TODO
1111
// code = escapeHtml(code)

packages/vue-markdown-loader/src/markdown/lib/tableOfContents.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default (md, options) => {
1313
options = Object.assign({}, defaults, options)
1414
const tocRegexp = options.markerPattern
1515

16-
function toc (state, silent) {
16+
function toc(state, silent) {
1717
let token
1818
let match
1919

@@ -30,9 +30,9 @@ export default (md, options) => {
3030
match = tocRegexp.exec(state.src)
3131
match = !match
3232
? []
33-
: match.filter(function (m) {
34-
return m
35-
})
33+
: match.filter(function(m) {
34+
return m
35+
})
3636
if (match.length < 1) {
3737
return false
3838
}
@@ -54,22 +54,22 @@ export default (md, options) => {
5454
return true
5555
}
5656

57-
md.renderer.rules.toc_open = function () {
57+
md.renderer.rules.toc_open = function() {
5858
return vBindEscape`<TOC
5959
:class=${options.containerClass}
6060
:list-type=${options.listType}
6161
:include-level=${options.includeLevel}
6262
>`
6363
}
6464

65-
md.renderer.rules.toc_body = function () {
65+
md.renderer.rules.toc_body = function() {
6666
return (
6767
`<template slot="header">${options.containerHeaderHtml}</template>` +
6868
`<template slot="footer">${options.containerFooterHtml}</template>`
6969
)
7070
}
7171

72-
md.renderer.rules.toc_close = function () {
72+
md.renderer.rules.toc_close = function() {
7373
return `</TOC>`
7474
}
7575

@@ -78,16 +78,16 @@ export default (md, options) => {
7878
}
7979

8080
/** escape double quotes in v-bind derivatives */
81-
function vBindEscape (strs, ...args) {
81+
function vBindEscape(strs, ...args) {
8282
return strs.reduce((prev, curr, index) => {
8383
return (
8484
prev +
8585
curr +
8686
(index >= args.length
8787
? ''
8888
: `"${JSON.stringify(args[index])
89-
.replace(/"/g, "'")
90-
.replace(/([^\\])(\\\\)*\\'/g, (_, char) => char + '\\u0022')}"`)
89+
.replace(/"/g, "'")
90+
.replace(/([^\\])(\\\\)*\\'/g, (_, char) => char + '\\u0022')}"`)
9191
)
9292
}, '')
9393
}

packages/vue-markdown-loader/src/utils/codegen.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
* Convert paths string to real-world import code.
33
*/
44

5-
export function pathsToModuleCode (files: string[]) {
5+
export function pathsToModuleCode(files: string[]) {
66
let index = 0
77
let code = ''
88

9-
code += files
10-
.map(filePath => `import m${index++} from ${JSON.stringify(filePath)}`)
11-
.join('\n')
9+
code += files.map(filePath => `import m${index++} from ${JSON.stringify(filePath)}`).join('\n')
1210

1311
code += '\n\nexport default [\n'
1412

packages/vue-markdown-loader/src/utils/compose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
type Pipe<T, U> = (...args: T[]) => U
66

7-
export = function compose<T> (...processors: Array<Pipe<any, T>>): Pipe<any, T> {
7+
export = function compose<T>(...processors: Array<Pipe<any, T>>): Pipe<any, T> {
88
if (processors.length === 0) return (input: T) => input
99
if (processors.length === 1) return processors[0]
1010
return processors.reduce((prev, next) => {

packages/vue-markdown-loader/src/utils/datatypes.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const isNull = (x: any) => x === null
2020
export const isNullOrUndefined = (x: any) => isUndefined(x) || isNull(x)
2121

2222
export const toRawType = (value: any) => _toString.call(value).slice(8, -1)
23-
export const getType = function (fn: any) {
23+
export const getType = function(fn: any) {
2424
const match = fn && fn.toString().match(/^\s*function (\w+)/)
2525
return match ? match[1] : ''
2626
}
@@ -33,7 +33,7 @@ export const getType = function (fn: any) {
3333
*/
3434
type Type = String | Number | Boolean | RegExp | Function | Record<string, any> | Array<any>
3535

36-
function toNaturalMultiTypesLanguage (types: Type[]) {
36+
function toNaturalMultiTypesLanguage(types: Type[]) {
3737
const len = types.length
3838
if (len === 1) {
3939
return types.join('')
@@ -43,7 +43,7 @@ function toNaturalMultiTypesLanguage (types: Type[]) {
4343
return rest.join(', ') + ' or ' + last
4444
}
4545

46-
export function assertTypes (value: any, types: Type[]) {
46+
export function assertTypes(value: any, types: Type[]) {
4747
let valid
4848
let warnMsg
4949
let actualType = toRawType(value)
@@ -61,8 +61,7 @@ export function assertTypes (value: any, types: Type[]) {
6161

6262
if (!valid) {
6363
warnMsg =
64-
`expected a ${chalk.green(toNaturalMultiTypesLanguage(expectedTypes))} ` +
65-
`but got ${chalk.yellow(actualType)}.`
64+
`expected a ${chalk.green(toNaturalMultiTypesLanguage(expectedTypes))} ` + `but got ${chalk.yellow(actualType)}.`
6665
}
6766

6867
return { valid, warnMsg }
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export = function ensureEndingSlash (path: string): string {
2-
return /(\.html|\/)$/.test(path)
3-
? path
4-
: path + '/'
1+
export = function ensureEndingSlash(path: string): string {
2+
return /(\.html|\/)$/.test(path) ? path : path + '/'
53
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export = function ensureLeadingSlash (path: string): string {
1+
export = function ensureLeadingSlash(path: string): string {
22
return path.replace(/^\/?/, '/')
33
}

packages/vue-markdown-loader/src/utils/env.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
class ENV {
2-
isDebug: boolean;
3-
isTest: boolean;
4-
isProduction: boolean;
2+
isDebug: boolean
3+
isTest: boolean
4+
isProduction: boolean
55

6-
constructor () {
6+
constructor() {
77
this.isDebug = false
88
this.isTest = process.env.NODE_ENV === 'test' || false
99
this.isProduction = false
1010
}
1111

12-
setOptions (options: Record<string, boolean>) {
12+
setOptions(options: Record<string, boolean>) {
1313
Object.assign(this, options)
1414
}
1515
}

packages/vue-markdown-loader/src/utils/extractHeaders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import deeplyParseHeaders from './deeplyParseHeaders'
1212

1313
const cache = new LRU({ max: 1000 })
1414

15-
export = function (content: string, include = [], md: any) {
15+
export = function(content: string, include = [], md: any) {
1616
const key = content + include.join(',')
1717
const hit = cache.get(key)
1818
if (hit) {
@@ -27,7 +27,7 @@ export = function (content: string, include = [], md: any) {
2727
if (t.type === 'heading_open' && include.includes(t.tag)) {
2828
const title = tokens[i + 1].content
2929
// @ts-ignore
30-
const slug = (t.attrs).find(([name]) => name === 'id')[1]
30+
const slug = t.attrs.find(([name]) => name === 'id')[1]
3131
res.push({
3232
level: parseInt(t.tag.slice(1), 10),
3333
title: deeplyParseHeaders(title),

packages/vue-markdown-loader/src/utils/fallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs-extra'
22

3-
export function fsExistsFallback (files: string[]): string | void {
3+
export function fsExistsFallback(files: string[]): string | void {
44
for (const file of files) {
55
if (fs.existsSync(file)) {
66
return file

packages/vue-markdown-loader/src/utils/fileToPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { indexRE, isIndexFile } from './isIndexFile'
22

33
const extRE = /\.(vue|md)$/
44

5-
export = function fileToPath (file: string): string {
5+
export = function fileToPath(file: string): string {
66
if (isIndexFile(file)) {
77
// README.md -> /
88
// README.vue -> /

0 commit comments

Comments
 (0)