experimental linters
commit 5b31740d967bb61bfed6a2338d07e8fc6e4957b3 Author: Hans Pagel <hans.pagel@ueber.io> Date: Tue Jan 19 14:48:00 2021 +0100 refactoring, disable TS checks for now commit 6fcc5082287ba4dd5457b8ea6e6d8300efaaafb6 Author: Hans Pagel <hans.pagel@ueber.io> Date: Tue Jan 19 14:42:14 2021 +0100 move everything to a new experiments structure commit 2b5f394ad4c916f7ac364fa03d05e2f4311e9b1d Author: Hans Pagel <hans.pagel@ueber.io> Date: Mon Jan 18 20:22:35 2021 +0100 refactoring commit 91a3747adca114fbce0972a2a2efa751e94d4ea4 Author: Hans Pagel <hans.pagel@ueber.io> Date: Mon Jan 18 17:48:59 2021 +0100 refactoring commit 4550fa70059060b6702425970ba33bcf6a0f3e66 Author: Hans Pagel <hans.pagel@ueber.io> Date: Mon Jan 18 17:37:43 2021 +0100 load plugins in the example commit a7087af14044673c587c233c44a5e767ff23b160 Author: Hans Pagel <hans.pagel@ueber.io> Date: Mon Jan 18 17:31:47 2021 +0100 init new linter plugin
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import LinterPlugin from '../LinterPlugin'
|
||||
|
||||
export class BadWords extends LinterPlugin {
|
||||
|
||||
public regex = /\b(obviously|clearly|evidently|simply)\b/ig
|
||||
|
||||
scan() {
|
||||
this.doc.descendants((node: any, position: any) => {
|
||||
if (!node.isText) {
|
||||
return
|
||||
}
|
||||
|
||||
const matches = this.regex.exec(node.text)
|
||||
|
||||
if (matches) {
|
||||
this.record(
|
||||
`Try not to say '${matches[0]}'`,
|
||||
position + matches.index, position + matches.index + matches[0].length,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// @ts-nocheck
|
||||
import LinterPlugin from '../LinterPlugin'
|
||||
|
||||
export class HeadingLevel extends LinterPlugin {
|
||||
fixHeader(level) {
|
||||
return function ({ state, dispatch }) {
|
||||
dispatch(state.tr.setNodeMarkup(this.from - 1, null, { level }))
|
||||
}
|
||||
}
|
||||
|
||||
scan() {
|
||||
let lastHeadLevel = null
|
||||
|
||||
this.doc.descendants((node, position) => {
|
||||
if (node.type.name == 'heading') {
|
||||
// Check whether heading levels fit under the current level
|
||||
const { level } = node.attrs
|
||||
|
||||
if (lastHeadLevel != null && level > lastHeadLevel + 1) {
|
||||
this.record(`Heading too small (${level} under ${lastHeadLevel})`,
|
||||
position + 1, position + 1 + node.content.size,
|
||||
this.fixHeader(lastHeadLevel + 1))
|
||||
}
|
||||
lastHeadLevel = level
|
||||
}
|
||||
})
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import LinterPlugin from '../LinterPlugin'
|
||||
|
||||
export class Punctuation extends LinterPlugin {
|
||||
public regex = / ([,.!?:]) ?/g
|
||||
|
||||
fix(replacement: any) {
|
||||
return function ({ state, dispatch }) {
|
||||
dispatch(
|
||||
state.tr.replaceWith(
|
||||
this.from, this.to,
|
||||
state.schema.text(replacement),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
scan() {
|
||||
this.doc.descendants((node, position) => {
|
||||
if (!node.isText) {
|
||||
return
|
||||
}
|
||||
|
||||
const matches = this.regex.exec(node.text)
|
||||
|
||||
if (matches) {
|
||||
this.record(
|
||||
'Suspicious spacing around punctuation',
|
||||
position + matches.index, position + matches.index + matches[0].length,
|
||||
this.fix(`${matches[1]} `),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user