-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Extend test coverage for general code style cases
Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
30 changed files
with
433 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
version = 1 | ||
SPDX-PackageName = "eslint-config" | ||
SPDX-PackageSupplier = "Nextcloud <[email protected]>" | ||
|
@@ -12,7 +13,19 @@ SPDX-FileCopyrightText = "2019 Nextcloud GmbH and Nextcloud contributors" | |
SPDX-License-Identifier = "AGPL-3.0-or-later" | ||
|
||
[[annotations]] | ||
path = ["tsconfig.json"] | ||
path = ["tsconfig.json", "tests/tsconfig.json"] | ||
precedence = "aggregate" | ||
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors" | ||
SPDX-License-Identifier = "CC0-1.0" | ||
|
||
# Test fixtures might not be able to have headers (as e.g. the header is tested) | ||
[[annotations]] | ||
path = [ | ||
"tests/fixtures/codestyle/input/*.ts", | ||
"tests/fixtures/codestyle/input/*.js", | ||
"tests/fixtures/codestyle/output/*.ts", | ||
"tests/fixtures/codestyle/output/*.js" | ||
] | ||
precedence = "aggregate" | ||
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors" | ||
SPDX-License-Identifier = "AGPL-3.0-or-later" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { Linter } from 'eslint' | ||
|
||
import { ESLint } from 'eslint' | ||
import { expect, test } from 'vitest' | ||
import * as path from 'path' | ||
import * as eslintConfig from '../lib/index.js' | ||
|
||
const eslint = new ESLint({ | ||
fix: true, | ||
overrideConfigFile: true, | ||
overrideConfig: eslintConfig.recommended as Linter.Config<Linter.RulesRecord>, | ||
}) | ||
|
||
const lintFile = async (file) => { | ||
const real = path.resolve(path.join(__dirname, file)) | ||
return await eslint.lintFiles(real) | ||
} | ||
|
||
test.for([ | ||
'array', | ||
'arrow-function', | ||
'function', | ||
'indention', | ||
'objects', | ||
'quotes', | ||
'semicolons', | ||
])('Code style', async (testCase: string) => { | ||
const results = await lintFile(`fixtures/codestyle/input/${testCase}.{t,j}s`) | ||
expect(results).toHaveLength(1) | ||
expect(results[0].output).toMatchFileSnapshot(results[0].filePath.replace('input', 'output')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// this should be multi line | ||
const arr = ['first', 'second', 'third', 'and', 'so', 'on'] | ||
|
||
// this has a missing trailing comma causing too much git diff | ||
const arr2 = [ | ||
'first', | ||
'second', | ||
'third' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* An arrow function with the { on the wrong line | ||
*/ | ||
const arrow = (name: string) => | ||
{ | ||
// | ||
} | ||
|
||
// Arrow functions should always have parenthesis for readability | ||
const arr = ['myArray'].map(item => item.length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* A function with the { on the wrong line | ||
* | ||
* @param name | ||
*/ | ||
export function foo(name: string): boolean | ||
{ | ||
return true | ||
} | ||
|
||
/** | ||
* Also a function with the { on the wrong line | ||
* | ||
* @param firstName | ||
* @param lastName | ||
*/ | ||
export function bar( | ||
firstName: string, | ||
lastName: string, | ||
): boolean | ||
{ | ||
return false | ||
} | ||
|
||
/** | ||
* Parameters should always be either on the same line or have consistent new lines | ||
* | ||
* @param num | ||
* @param enable | ||
*/ | ||
export function doSomething(num: number, | ||
enable: boolean) { | ||
// ... | ||
} | ||
|
||
/** | ||
* Same here: Parameters should always be either on the same line or have consistent new lines | ||
* | ||
* @param num | ||
* @param enable | ||
*/ | ||
export function doSomethingDifferent( | ||
num: number, enable: boolean | ||
) { | ||
// ... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const obj = { | ||
foo: 'bar' | ||
} | ||
|
||
class Foo { | ||
a = 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Only quote if needed | ||
const obj = { | ||
'noQuotesNeeded': true, | ||
'quotes-needed': false, | ||
} | ||
|
||
// Prefer shorthand property | ||
const user = 'jdoe' | ||
const obj2 = { | ||
user: user, | ||
id: 123, | ||
} | ||
|
||
// Require spaces around braces | ||
const obj3 = {first: 1} | ||
|
||
// Prefer multi line objects | ||
const obj4 = { first: 1, second: 'two' } | ||
|
||
// Use trailing commas to be git diff friendly | ||
const obj5 = { | ||
first: 1, | ||
second: 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const foo = "foo" | ||
const bar = 'bar' | ||
const baz = `baz` | ||
const escape = `Escape 'the' single quote` | ||
const escape2 = "Escape 'the' single quote" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const text = 'foo'; | ||
console.log(text); | ||
|
||
const other = 'foo' | ||
;[ | ||
'1', | ||
'2', | ||
].map(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// this should be multi line | ||
const arr = [ | ||
'first', | ||
'second', | ||
'third', | ||
'and', | ||
'so', | ||
'on', | ||
] | ||
|
||
// this has a missing trailing comma causing too much git diff | ||
const arr2 = [ | ||
'first', | ||
'second', | ||
'third', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* An arrow function with the { on the wrong line | ||
* | ||
* @param name | ||
*/ | ||
const arrow = (name: string) => { | ||
// | ||
} | ||
|
||
// Arrow functions should always have parenthesis for readability | ||
const arr = ['myArray'].map((item) => item.length) |
Oops, something went wrong.