mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[eslint-plugin] integrate with build scripts (#35176)
GitOrigin-RevId: cc042f70981da3862f2660c695193190b0c62000
This commit is contained in:
@@ -9,12 +9,19 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/json": "^2.0.0",
|
||||
"@typescript-eslint/parser": "^8.59.4"
|
||||
"@typescript-eslint/parser": "^8.59.4",
|
||||
"typescript": "^5.0.4",
|
||||
"vitest": "4.1.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^10.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node rules.test.js"
|
||||
"test": "yarn run lint && yarn run types:check && yarn run test:unit",
|
||||
"lint": "eslint --cache --cache-location ../../.cache/eslint/ --ext .cjs,.js,.jsx,.mjs,.ts --max-warnings 0 --format unix .",
|
||||
"lint:fix": "eslint --cache --cache-location ../../.cache/eslint/ --fix --ext .cjs,.js,.jsx,.mjs,.ts .",
|
||||
"test:ci": "yarn run test:unit",
|
||||
"test:unit": "vitest --config vitest.config.ts",
|
||||
"types:check": "tsc --noEmit"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ const getSuggestion = routePath => {
|
||||
|
||||
if (routePath instanceof RegExp) {
|
||||
const words = removeTextBetweenBrackets(routePath.source).match(/[\w-]+/g)
|
||||
if (!words) return routePath
|
||||
if (!words) return null
|
||||
|
||||
let newSource = routePath.source
|
||||
for (const word of words) {
|
||||
@@ -42,9 +42,7 @@ const getSuggestion = routePath => {
|
||||
}
|
||||
|
||||
const kebabed = new RegExp(newSource, routePath.flags)
|
||||
return kebabed.source.toString() === routePath.source.toString()
|
||||
? null
|
||||
: kebabed
|
||||
return kebabed.source === routePath.source ? null : kebabed.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { afterAll, describe, it } from 'vitest'
|
||||
import { RuleTester } from 'eslint'
|
||||
|
||||
// ESLint's RuleTester discovers the test framework via these hooks. The repo's
|
||||
// vitest configs deliberately avoid `globals: true`, so wire them explicitly.
|
||||
RuleTester.afterAll = afterAll
|
||||
RuleTester.describe = describe
|
||||
RuleTester.it = it
|
||||
RuleTester.itOnly = it.only
|
||||
+32
-21
@@ -1,18 +1,21 @@
|
||||
const { RuleTester } = require('eslint')
|
||||
const tsParser = require('@typescript-eslint/parser')
|
||||
const json = require('@eslint/json').default
|
||||
const noThrowInCallback = require('./no-throw-in-callback')
|
||||
const preferKebabUrl = require('./prefer-kebab-url')
|
||||
const noUnnecessaryTrans = require('./no-unnecessary-trans')
|
||||
const shouldUnescapeTrans = require('./should-unescape-trans')
|
||||
const noGeneratedEditorThemes = require('./no-generated-editor-themes')
|
||||
const viDoMockValidPath = require('./require-vi-doMock-valid-path')
|
||||
const requireCioSnakeCaseProperties = require('./require-cio-snake-case-properties')
|
||||
const requireRelForDocsLinks = require('./require-rel-for-docs-links')
|
||||
const noConsecutiveSpacesInLocales = require('./no-consecutive-spaces-in-locales')
|
||||
const noStraightApostrophesInLocales = require('./no-straight-apostrophes-in-locales')
|
||||
const frenchTypographyInLocales = require('./french-typography-in-locales')
|
||||
const sortedKeysInLocales = require('./sorted-keys-in-locales')
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { RuleTester } from 'eslint'
|
||||
import tsParser from '@typescript-eslint/parser'
|
||||
import json from '@eslint/json'
|
||||
import noThrowInCallback from '../../no-throw-in-callback.js'
|
||||
import preferKebabUrl from '../../prefer-kebab-url.js'
|
||||
import noUnnecessaryTrans from '../../no-unnecessary-trans.js'
|
||||
import shouldUnescapeTrans from '../../should-unescape-trans.js'
|
||||
import noGeneratedEditorThemes from '../../no-generated-editor-themes.js'
|
||||
import viDoMockValidPath from '../../require-vi-doMock-valid-path.js'
|
||||
import requireCioSnakeCaseProperties from '../../require-cio-snake-case-properties.js'
|
||||
import requireRelForDocsLinks from '../../require-rel-for-docs-links.js'
|
||||
import noConsecutiveSpacesInLocales from '../../no-consecutive-spaces-in-locales.js'
|
||||
import noStraightApostrophesInLocales from '../../no-straight-apostrophes-in-locales.js'
|
||||
import frenchTypographyInLocales from '../../french-typography-in-locales.js'
|
||||
import sortedKeysInLocales from '../../sorted-keys-in-locales.js'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
languageOptions: {
|
||||
@@ -64,7 +67,15 @@ ruleTester.run('prefer-kebab-url', preferKebabUrl, {
|
||||
{
|
||||
code: `router.get(/^\\/downLoad\\/pro-ject\\/([^/]*)\\/OutPut\\/out-put\\.pdf$/)`,
|
||||
errors: [
|
||||
{ message: 'Route path should be in kebab-case.', suggestions: 1 },
|
||||
{
|
||||
message: 'Route path should be in kebab-case.',
|
||||
suggestions: [
|
||||
{
|
||||
desc: 'Change to kebab-case: /^\\/down-load\\/pro-ject\\/([^/]*)\\/out-put\\/out-put\\.pdf$/',
|
||||
output: `router.get(/^\\/down-load\\/pro-ject\\/([^/]*)\\/out-put\\/out-put\\.pdf$/)`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -157,28 +168,28 @@ ruleTester.run('no-generated-editor-themes', noGeneratedEditorThemes, {
|
||||
ruleTester.run('domock-require-valid-path', viDoMockValidPath, {
|
||||
valid: [
|
||||
{
|
||||
code: 'vi.doMock("./require-vi-doMock-valid-path.js")',
|
||||
code: 'vi.doMock("../../require-vi-doMock-valid-path.js")',
|
||||
filename: __filename,
|
||||
},
|
||||
{
|
||||
code: 'const filename = "./require-vi-doMock-valid-path.js"; vi.doMock(filename);',
|
||||
code: 'const filename = "../../require-vi-doMock-valid-path.js"; vi.doMock(filename);',
|
||||
filename: __filename,
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: "vi.doMock('./require-vi-doMock-valid-path2')",
|
||||
code: "vi.doMock('../../require-vi-doMock-valid-path2')",
|
||||
filename: __filename,
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'The path "./require-vi-doMock-valid-path2" in vi.doMock() cannot be resolved relative to the current file.',
|
||||
'The path "../../require-vi-doMock-valid-path2" in vi.doMock() cannot be resolved relative to the current file.',
|
||||
suggestions: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'const filename = "./require-vi-doMock-valid-path2.js"; vi.doMock(filename);',
|
||||
code: 'const filename = "../../require-vi-doMock-valid-path2.js"; vi.doMock(filename);',
|
||||
filename: __filename,
|
||||
errors: [
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.backend.json",
|
||||
"include": ["**/*.js"]
|
||||
"include": ["**/*.js", "**/*.cjs", "**/*.ts"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { defineConfig, ViteUserConfig } from 'vitest/config'
|
||||
|
||||
let reporterOptions: ViteUserConfig['test'] = {}
|
||||
if (process.env.CI) {
|
||||
reporterOptions = {
|
||||
reporters: [
|
||||
'default',
|
||||
[
|
||||
'junit',
|
||||
{
|
||||
classnameTemplate: `Unit tests.{filename}`,
|
||||
},
|
||||
],
|
||||
],
|
||||
outputFile: 'reports/junit-vitest-unit.xml',
|
||||
}
|
||||
}
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['test/unit/**/*.test.{js,ts}'],
|
||||
setupFiles: ['./test/setup.js'],
|
||||
isolate: false,
|
||||
...reporterOptions,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user