Skip to content

Commit

Permalink
chore: add lint-eslint.yml
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jul 4, 2023
1 parent 4629f39 commit 9157b7b
Show file tree
Hide file tree
Showing 26 changed files with 8,745 additions and 2,645 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: [
'@nextcloud/eslint-config/typescript',
],
settings: {
jsdoc: {
mode: 'typescript',
},
},
}
62 changes: 62 additions & 0 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# Use lint-eslint together with lint-eslint-when-unrelated to make eslint a required check for GitHub actions
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks

name: Lint eslint

on:
pull_request:
paths:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.*'
- '.eslintignore'
- '**.js'
- '**.ts'
- '**.vue'

permissions:
contents: read

concurrency:
group: lint-eslint-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: eslint

steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
id: versions
with:
fallbackNode: '^20'
fallbackNpm: '^9'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint
9 changes: 6 additions & 3 deletions __tests__/fileAction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable no-new */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { getFileActions, registerFileAction, FileAction } from '../lib/fileAction'
import logger from '../lib/utils/logger';
import logger from '../lib/utils/logger'

describe('FileActions init', () => {

Expand Down Expand Up @@ -165,7 +168,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
inline: () => true,
renderInline: false
renderInline: false,
} as any as FileAction)
}).toThrowError('Invalid renderInline function')
})
Expand Down Expand Up @@ -202,4 +205,4 @@ describe('FileActions creation', () => {
expect(action.inline?.({} as any, {})).toBe(true)
expect(action.renderInline?.({} as any, {}).outerHTML).toBe('<span>test</span>')
})
})
})
17 changes: 8 additions & 9 deletions __tests__/files/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('File creation', () => {
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma'
root: '/files/emma',
})

expect(file).toBeInstanceOf(File)
Expand All @@ -66,7 +66,7 @@ describe('File creation', () => {
const file = new File({
source: 'https://domain.com/Photos/picture.jpg',
mime: 'image/jpeg',
owner: null
owner: null,
})

expect(file).toBeInstanceOf(File)
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('File data change', () => {
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma'
root: '/files/emma',
})

expect(file.basename).toBe('picture.jpg')
Expand All @@ -170,7 +170,6 @@ describe('File data change', () => {
})
})


describe('Altering attributes updates mtime', () => {
test('mtime is updated on existing attribute', () => {
const file = new File({
Expand All @@ -179,12 +178,12 @@ describe('Altering attributes updates mtime', () => {
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
attributes: {
test: true
test: true,
},
})
expect(file.attributes.test).toBe(true)
file.attributes.test = false

// Check that mtime has been updated
expect(file.mtime?.getDate()).toBe(new Date().getDate())
expect(file.attributes.test).toBe(false)
Expand All @@ -199,7 +198,7 @@ describe('Altering attributes updates mtime', () => {
})
expect(file.attributes.test).toBeFalsy()
file.attributes.test = true

// Check that mtime has been updated
expect(file.mtime?.getDate()).toBe(new Date().getDate())
expect(file.attributes.test).toBe(true)
Expand All @@ -212,12 +211,12 @@ describe('Altering attributes updates mtime', () => {
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
attributes: {
test: true
test: true,
},
})
expect(file.attributes.test).toBe(true)
delete file.attributes.test

// Check that mtime has been updated
expect(file.mtime?.getDate()).toBe(new Date().getDate())
expect(file.attributes.test).toBeUndefined()
Expand Down
12 changes: 6 additions & 6 deletions __tests__/files/folder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Folder creation', () => {
test('Valid dav folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma'
owner: 'emma',
})

expect(folder).toBeInstanceOf(Folder)
Expand All @@ -31,7 +31,7 @@ describe('Folder creation', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/Berlin',
owner: 'emma',
root: '/files/emma'
root: '/files/emma',
})

expect(folder).toBeInstanceOf(Folder)
Expand All @@ -55,7 +55,7 @@ describe('Folder creation', () => {
test('Valid remote folder', () => {
const folder = new Folder({
source: 'https://domain.com/Photos/',
owner: null
owner: null,
})

expect(folder).toBeInstanceOf(Folder)
Expand All @@ -81,7 +81,7 @@ describe('Folder data change', () => {
test('Rename a folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos',
owner: 'emma'
owner: 'emma',
})

expect(folder.basename).toBe('Photos')
Expand All @@ -99,7 +99,7 @@ describe('Folder data change', () => {
test('Moving a folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma'
owner: 'emma',
})

expect(folder.basename).toBe('Photos')
Expand All @@ -118,7 +118,7 @@ describe('Folder data change', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma',
root: '/files/emma'
root: '/files/emma',
})

expect(folder.basename).toBe('Photos')
Expand Down
25 changes: 12 additions & 13 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ describe('Node testing', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
mime: 'image/jpeg',
owner: 'emma'
owner: 'emma',
})
expect(file.root).toBeNull()
})

test('Remove source ending slash', () => {
const file = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma'
owner: 'emma',
})
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos')
})

test('Invalid rename', () => {
const file = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma'
owner: 'emma',
})
expect(() => file.rename('new/folder')).toThrowError('Invalid basename')
})
Expand All @@ -35,7 +35,7 @@ describe('FileId attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
mime: 'image/jpeg',
owner: 'emma'
owner: 'emma',
})
expect(file.fileid).toBeUndefined()
})
Expand All @@ -46,8 +46,8 @@ describe('FileId attribute', () => {
mime: 'image/jpeg',
owner: 'emma',
attributes: {
fileid: 1234
}
fileid: 1234,
},
})
expect(file.fileid).toBe(1234)
})
Expand Down Expand Up @@ -75,17 +75,17 @@ describe('Sanity checks', () => {
expect(() => new File({
source: 'cloud.domain.com/remote.php/dav/Photos',
mime: 'image/jpeg',
owner: 'emma'
owner: 'emma',
})).toThrowError('Invalid source')
expect(() => new File({
source: '/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma'
owner: 'emma',
})).toThrowError('Invalid source format, source must be a valid URL')
expect(() => new File({
source: 'ftp://remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma'
owner: 'emma',
})).toThrowError('Invalid source format, only http(s) is supported')
})

Expand All @@ -94,25 +94,24 @@ describe('Sanity checks', () => {
source: 'https://cloud.domain.com/remote.php/dav/Photos',
mime: 'image',
owner: 'emma',
mtime: 'invalid' as unknown as Date
mtime: 'invalid' as unknown as Date,
})).toThrowError('Invalid mtime type')
})


test('Invalid crtime', () => {
expect(() => new File({
source: 'https://cloud.domain.com/remote.php/dav/Photos',
mime: 'image',
owner: 'emma',
crtime: 'invalid' as unknown as Date
crtime: 'invalid' as unknown as Date,
})).toThrowError('Invalid crtime type')
})

test('Invalid mime', () => {
expect(() => new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image',
owner: 'emma'
owner: 'emma',
})).toThrowError('Missing or invalid mandatory mime')
})

Expand Down
Loading

0 comments on commit 9157b7b

Please sign in to comment.