Skip to content

Commit a103e4f

Browse files
committed
fix(lint): also lint tests except fixtures
Signed-off-by: Max <max@nextcloud.com>
1 parent ab40a49 commit a103e4f

32 files changed

Lines changed: 397 additions & 404 deletions

.eslintignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33

4-
src/tests/
5-
*.d.ts
4+
src/tests/fixtures

src/markdownit/details.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ const DETAILS_START_REGEX = /^<details>\s*$/
1111
const DETAILS_END_REGEX = /^<\/details>\s*$/
1212
const SUMMARY_REGEX = /(?<=^<summary>).*(?=<\/summary>\s*$)/
1313

14+
/**
15+
*
16+
* @param state
17+
* @param startLine
18+
* @param endLine
19+
* @param silent
20+
*/
1421
function parseDetails(state: StateBlock, startLine: number, endLine: number, silent: boolean) {
1522
// let autoClosedBlock = false
1623
let start = state.bMarks[startLine] + state.tShift[startLine]
@@ -76,20 +83,20 @@ function parseDetails(state: StateBlock, startLine: number, endLine: number, sil
7683
state.parentType = 'reference'
7784

7885
// This will prevent lazy continuations from ever going past our end marker
79-
state.lineMax = nextLine;
86+
state.lineMax = nextLine
8087

8188
// Push tokens to the state
8289

8390
let token = state.push('details_open', 'details', 1)
8491
token.block = true
8592
token.info = detailsSummary
86-
token.map = [ startLine, nextLine ]
93+
token.map = [startLine, nextLine]
8794

8895
token = state.push('details_summary', 'summary', 1)
8996
token.block = false
9097

9198
// Parse and push summary to preserve markup
92-
let tokens: Token[] = []
99+
const tokens: Token[] = []
93100
state.md.inline.parse(detailsSummary, state.md, state.env, tokens)
94101
for (const t of tokens) {
95102
token = state.push(t.type, t.tag, t.nesting)
@@ -100,7 +107,7 @@ function parseDetails(state: StateBlock, startLine: number, endLine: number, sil
100107

101108
token = state.push('details_summary', 'summary', -1)
102109

103-
state.md.block.tokenize(state, startLine + 2, nextLine);
110+
state.md.block.tokenize(state, startLine + 2, nextLine)
104111

105112
token = state.push('details_close', 'details', -1)
106113
token.block = true
@@ -117,6 +124,6 @@ function parseDetails(state: StateBlock, startLine: number, endLine: number, sil
117124
*/
118125
export default function details(md: MarkdownIt) {
119126
md.block.ruler.before('fence', 'details', parseDetails, {
120-
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ],
127+
alt: ['paragraph', 'reference', 'blockquote', 'list'],
121128
})
122129
}

src/tests/builders.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { expect } from '@jest/globals';
7-
import { Mark, Node } from '@tiptap/pm/model'
6+
// eslint-disable-next-line n/no-extraneous-import
7+
import { expect } from '@jest/globals'
8+
import { Node } from '@tiptap/pm/model'
89
import { builders } from 'prosemirror-test-builder'
9-
import { createRichEditor } from '../EditorFactory'
10-
10+
import { createRichEditor } from '../EditorFactory.js'
1111

12+
/**
13+
* Get node builders from the default rich editor.
14+
* @return {object}
15+
*/
1216
export function getBuilders() {
1317
const editor = createRichEditor()
1418
return builders(editor.schema, {
@@ -34,34 +38,24 @@ export const thead = getBuilders().thead
3438

3539
/**
3640
* Create string representation of prosemirror / TipTap Node with attributes
37-
* @param {Node} node
38-
* @returns {string}
41+
* @param {Node} node to serialize
42+
* @return {string}
3943
*/
4044
function createDocumentString(node) {
41-
/**
42-
* Extract attributes of node or mark
43-
* @param {Node|Mark} node
44-
* @returns {string}
45-
*/
4645
const extractAttributes = (node) => {
4746
const attrs = node.attrs || {}
4847
const attrString = Object.keys(attrs)
4948
.map((key) => {
5049
// null is the TipTap default so we ignore it (e.g. a value of `unknown` must be manually set by the application)
51-
if (attrs[key] !== null) {
52-
return key + '=' + (typeof attrs[key] === 'string' ? `"${attrs[key]}"` : attrs[key])
53-
}
50+
return (attrs[key] === null)
51+
? undefined
52+
: key + '=' + (typeof attrs[key] === 'string' ? `"${attrs[key]}"` : attrs[key])
5453
})
5554
.filter(v => !!v)
5655
.join(',')
5756
return attrString ? `<${attrString}>` : ''
5857
}
5958

60-
/**
61-
* Create string representation of a single Node
62-
* @param {Node} node
63-
* @returns {string}
64-
*/
6559
const stringifyNode = (node) => {
6660
const name = node.type.name
6761
if (name === 'text') return '"' + node.text.replace('"', '\\"').replace('\n', '\\n') + '"'
@@ -83,9 +77,9 @@ function createDocumentString(node) {
8377
* @example
8478
* const editor = createRichEditor()
8579
* expectDocument(editor.state.doc, table(
86-
* tr(
87-
* td('foo')
88-
* )
80+
* tr(
81+
* td('foo')
82+
* )
8983
* ))
9084
*/
9185
export function expectDocument(subject, expected) {

src/tests/extensions/Markdown.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import { Markdown } from './../../extensions/index.js'
77
import { createMarkdownSerializer } from './../../extensions/Markdown.js'
8-
import CodeBlock from '@tiptap/extension-code-block'
9-
import Blockquote from '@tiptap/extension-blockquote'
8+
import { CodeBlock } from '@tiptap/extension-code-block'
9+
import { Blockquote } from '@tiptap/extension-blockquote'
1010
import Image from './../../nodes/Image.js'
1111
import ImageInline from './../../nodes/ImageInline.js'
1212
import TaskList from './../../nodes/TaskList.js'
1313
import TaskItem from './../../nodes/TaskItem.js'
14-
import { Italic, Strong, Underline, Link} from './../../marks/index.js'
14+
import { Italic, Strong, Underline, Link } from './../../marks/index.js'
1515
import TiptapImage from '@tiptap/extension-image'
1616
import { getExtensionField } from '@tiptap/core'
1717
import { __serializeForClipboard as serializeForClipboard } from '@tiptap/pm/view'
@@ -114,7 +114,7 @@ describe('Markdown extension integrated in the editor', () => {
114114

115115
it('copies address from blockquote to markdown', () => {
116116
const editor = createCustomEditor({
117-
content: '<blockquote><p>Hermannsreute 44A</p></blockquote>',
117+
content: '<blockquote><p>Hermannsreute 44A</p></blockquote>',
118118
extensions: [Markdown, Blockquote],
119119
})
120120
const text = copyEditorContent(editor)
@@ -123,7 +123,7 @@ describe('Markdown extension integrated in the editor', () => {
123123

124124
it('copy version number without escape character', () => {
125125
const editor = createCustomEditor({
126-
content: '<p>Hello</p><p>28.0.4</p>',
126+
content: '<p>Hello</p><p>28.0.4</p>',
127127
extensions: [Markdown],
128128
})
129129
const text = copyEditorContent(editor)
@@ -132,7 +132,7 @@ describe('Markdown extension integrated in the editor', () => {
132132

133133
it('strips bold, italic, and other marks from paragraph', () => {
134134
const editor = createCustomEditor({
135-
content: '<p><strong>Hello</strong></p><p><span style="text-decoration: underline;">lonely </span><em>world</em></p>',
135+
content: '<p><strong>Hello</strong></p><p><span style="text-decoration: underline;">lonely </span><em>world</em></p>',
136136
extensions: [Markdown, Italic, Strong, Underline],
137137
})
138138
const text = copyEditorContent(editor)
@@ -141,7 +141,7 @@ describe('Markdown extension integrated in the editor', () => {
141141

142142
it('strips href and link formatting from email address', () => {
143143
const editor = createCustomEditor({
144-
content: '<p>Hello</p><p><a href="mailto:example@example.com">example@example.com</a></p>',
144+
content: '<p>Hello</p><p><a href="mailto:example@example.com">example@example.com</a></p>',
145145
extensions: [Markdown, Link],
146146
})
147147
const text = copyEditorContent(editor)
@@ -150,7 +150,7 @@ describe('Markdown extension integrated in the editor', () => {
150150

151151
})
152152

153-
function copyEditorContent(editor) {
153+
const copyEditorContent = (editor) => {
154154
editor.commands.selectAll()
155155
const slice = editor.state.selection.content()
156156
const { text } = serializeForClipboard(editor.view, slice)

src/tests/helpers.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { createMarkdownSerializer } from '../extensions/Markdown'
6+
import { createMarkdownSerializer } from '../extensions/Markdown.js'
77
import { Editor } from '@tiptap/core'
88

9-
import Document from '@tiptap/extension-document'
10-
import Paragraph from '../nodes/Paragraph'
11-
import Text from '@tiptap/extension-text'
9+
import { Document } from '@tiptap/extension-document'
10+
import { Text } from '@tiptap/extension-text'
11+
import Paragraph from '../nodes/Paragraph.js'
1212

13-
import { createRichEditor } from '../EditorFactory'
14-
import markdownit from '../markdownit'
13+
import { createRichEditor } from '../EditorFactory.js'
14+
import markdownit from '../markdownit/index.js'
1515

16+
/**
17+
*
18+
* @param {object} options for the editor
19+
* @param {string} options.content Content for the editor.
20+
* @param {Array} options.extensions Tip tap extensions
21+
*/
1622
export function createCustomEditor({ content, extensions }) {
1723
return new Editor({
1824
content,
@@ -21,15 +27,15 @@ export function createCustomEditor({ content, extensions }) {
2127
Paragraph,
2228
Text,
2329
...extensions,
24-
]
30+
],
2531
})
2632
}
2733

2834
/**
2935
* Ease markdown through TipTap editor and return serialized markdown
3036
*
31-
* @param {string} markdown
32-
* @returns {string}
37+
* @param {string} markdown to process
38+
* @return {string}
3339
*/
3440
export function markdownThroughEditor(markdown) {
3541
const tiptap = createRichEditor()
@@ -41,8 +47,8 @@ export function markdownThroughEditor(markdown) {
4147
/**
4248
* Ease HTML as input through the Editor and return the serialized markdown
4349
*
44-
* @param {string} html
45-
* @returns {string}
50+
* @param {string} html to process
51+
* @return {string}
4652
*/
4753
export function markdownThroughEditorHtml(html) {
4854
const tiptap = createRichEditor()
@@ -54,8 +60,8 @@ export function markdownThroughEditorHtml(html) {
5460
/**
5561
* Paste HTML into the Editor and return the serialized markdown
5662
*
57-
* @param {string} html
58-
* @returns {string}
63+
* @param {string} html to paste
64+
* @return {string}
5965
*/
6066
export function markdownFromPaste(html) {
6167
const tiptap = createRichEditor()

src/tests/helpers/base64.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { encodeArrayBuffer, decodeArrayBuffer } from '../../helpers/base64'
6+
import { encodeArrayBuffer, decodeArrayBuffer } from '../../helpers/base64.ts'
77

88
describe('encoding ArrayBuffer content', () => {
99
test('empty array buffer is empty base64 string', () => {
@@ -32,7 +32,7 @@ describe('decoding base64 to array buffer', () => {
3232
const encoded = 'AAAA'
3333
const buffer = decodeArrayBuffer(encoded)
3434
expect(buffer.byteLength).toBe(3)
35-
const view = new Uint8Array(buffer);
35+
const view = new Uint8Array(buffer)
3636
expect(view).toEqual(new Uint8Array([0, 0, 0]))
3737
})
3838
})

src/tests/helpers/links.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { domHref, parseHref } from '../../helpers/links'
6+
import { domHref, parseHref } from '../../helpers/links.js'
77
import { loadState } from '@nextcloud/initial-state'
88

99
global.OCA = {
@@ -13,7 +13,7 @@ global.OCA = {
1313
}
1414

1515
global.OC = {
16-
config: {modRewriteWorking: true},
16+
config: { modRewriteWorking: true },
1717
}
1818

1919
global._oc_webroot = ''
@@ -30,7 +30,7 @@ describe('Preparing href attributes for the DOM', () => {
3030
})
3131

3232
test('leave undefined hrefs alone', () => {
33-
expect(domHref({attrs: {}})).toBe(undefined)
33+
expect(domHref({ attrs: {} })).toBe(undefined)
3434
})
3535

3636
test('full url', () => {
@@ -88,8 +88,8 @@ describe('Extracting short urls from the DOM', () => {
8888

8989
describe('Inserting hrefs into the dom and extracting them again', () => {
9090

91-
function insertAndExtract(attrs) {
92-
const node = {attrs}
91+
const insertAndExtract = (attrs) => {
92+
const node = { attrs }
9393
const dom = {
9494
getAttribute() {
9595
return domHref(node)
@@ -99,35 +99,35 @@ describe('Inserting hrefs into the dom and extracting them again', () => {
9999
}
100100

101101
test('leave empty hrefs alone', () => {
102-
expect(insertAndExtract({href: ''})).toBe('')
102+
expect(insertAndExtract({ href: '' })).toBe('')
103103
})
104104

105105
test('leave undefined hrefs alone', () => {
106106
expect(insertAndExtract({})).toBe(undefined)
107107
})
108108

109109
test('old relative link format (from file picker) is rewritten', () => {
110-
expect(insertAndExtract({href: 'otherfile?fileId=123'}))
110+
expect(insertAndExtract({ href: 'otherfile?fileId=123' }))
111111
.toBe('http://localhost/f/123')
112112
})
113113

114114
test('old relative link format with ../ (from file picker) is rewritten', () => {
115-
expect(insertAndExtract({href: '../otherfile?fileId=123'}))
115+
expect(insertAndExtract({ href: '../otherfile?fileId=123' }))
116116
.toBe('http://localhost/f/123')
117117
})
118118

119119
test('old absolute link format (from file picker) is rewritten', () => {
120-
expect(insertAndExtract({href: '/otherfile?fileId=123'}))
120+
expect(insertAndExtract({ href: '/otherfile?fileId=123' }))
121121
.toBe('http://localhost/f/123')
122122
})
123123

124124
test('default full URL link format is unchanged', () => {
125-
expect(insertAndExtract({href: 'http://localhost/f/123'}))
125+
expect(insertAndExtract({ href: 'http://localhost/f/123' }))
126126
.toBe('http://localhost/f/123')
127127
})
128128

129129
test('absolute link to collectives page is unchanged', () => {
130-
expect(insertAndExtract({href: '/apps/collectives/page?fileId=123'}))
130+
expect(insertAndExtract({ href: '/apps/collectives/page?fileId=123' }))
131131
.toBe('/apps/collectives/page?fileId=123')
132132
})
133133

0 commit comments

Comments
 (0)