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": {
|
"devDependencies": {
|
||||||
"@eslint/json": "^2.0.0",
|
"@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": {
|
"peerDependencies": {
|
||||||
"eslint": "^10.4.0"
|
"eslint": "^10.4.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"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) {
|
if (routePath instanceof RegExp) {
|
||||||
const words = removeTextBetweenBrackets(routePath.source).match(/[\w-]+/g)
|
const words = removeTextBetweenBrackets(routePath.source).match(/[\w-]+/g)
|
||||||
if (!words) return routePath
|
if (!words) return null
|
||||||
|
|
||||||
let newSource = routePath.source
|
let newSource = routePath.source
|
||||||
for (const word of words) {
|
for (const word of words) {
|
||||||
@@ -42,9 +42,7 @@ const getSuggestion = routePath => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const kebabed = new RegExp(newSource, routePath.flags)
|
const kebabed = new RegExp(newSource, routePath.flags)
|
||||||
return kebabed.source.toString() === routePath.source.toString()
|
return kebabed.source === routePath.source ? null : kebabed.toString()
|
||||||
? null
|
|
||||||
: kebabed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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')
|
import { fileURLToPath } from 'node:url'
|
||||||
const tsParser = require('@typescript-eslint/parser')
|
import { RuleTester } from 'eslint'
|
||||||
const json = require('@eslint/json').default
|
import tsParser from '@typescript-eslint/parser'
|
||||||
const noThrowInCallback = require('./no-throw-in-callback')
|
import json from '@eslint/json'
|
||||||
const preferKebabUrl = require('./prefer-kebab-url')
|
import noThrowInCallback from '../../no-throw-in-callback.js'
|
||||||
const noUnnecessaryTrans = require('./no-unnecessary-trans')
|
import preferKebabUrl from '../../prefer-kebab-url.js'
|
||||||
const shouldUnescapeTrans = require('./should-unescape-trans')
|
import noUnnecessaryTrans from '../../no-unnecessary-trans.js'
|
||||||
const noGeneratedEditorThemes = require('./no-generated-editor-themes')
|
import shouldUnescapeTrans from '../../should-unescape-trans.js'
|
||||||
const viDoMockValidPath = require('./require-vi-doMock-valid-path')
|
import noGeneratedEditorThemes from '../../no-generated-editor-themes.js'
|
||||||
const requireCioSnakeCaseProperties = require('./require-cio-snake-case-properties')
|
import viDoMockValidPath from '../../require-vi-doMock-valid-path.js'
|
||||||
const requireRelForDocsLinks = require('./require-rel-for-docs-links')
|
import requireCioSnakeCaseProperties from '../../require-cio-snake-case-properties.js'
|
||||||
const noConsecutiveSpacesInLocales = require('./no-consecutive-spaces-in-locales')
|
import requireRelForDocsLinks from '../../require-rel-for-docs-links.js'
|
||||||
const noStraightApostrophesInLocales = require('./no-straight-apostrophes-in-locales')
|
import noConsecutiveSpacesInLocales from '../../no-consecutive-spaces-in-locales.js'
|
||||||
const frenchTypographyInLocales = require('./french-typography-in-locales')
|
import noStraightApostrophesInLocales from '../../no-straight-apostrophes-in-locales.js'
|
||||||
const sortedKeysInLocales = require('./sorted-keys-in-locales')
|
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({
|
const ruleTester = new RuleTester({
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
@@ -64,7 +67,15 @@ ruleTester.run('prefer-kebab-url', preferKebabUrl, {
|
|||||||
{
|
{
|
||||||
code: `router.get(/^\\/downLoad\\/pro-ject\\/([^/]*)\\/OutPut\\/out-put\\.pdf$/)`,
|
code: `router.get(/^\\/downLoad\\/pro-ject\\/([^/]*)\\/OutPut\\/out-put\\.pdf$/)`,
|
||||||
errors: [
|
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, {
|
ruleTester.run('domock-require-valid-path', viDoMockValidPath, {
|
||||||
valid: [
|
valid: [
|
||||||
{
|
{
|
||||||
code: 'vi.doMock("./require-vi-doMock-valid-path.js")',
|
code: 'vi.doMock("../../require-vi-doMock-valid-path.js")',
|
||||||
filename: __filename,
|
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,
|
filename: __filename,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
code: "vi.doMock('./require-vi-doMock-valid-path2')",
|
code: "vi.doMock('../../require-vi-doMock-valid-path2')",
|
||||||
filename: __filename,
|
filename: __filename,
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
message:
|
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: [],
|
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,
|
filename: __filename,
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.backend.json",
|
"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,
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -6843,6 +6843,8 @@ __metadata:
|
|||||||
"@eslint/json": "npm:^2.0.0"
|
"@eslint/json": "npm:^2.0.0"
|
||||||
"@typescript-eslint/parser": "npm:^8.59.4"
|
"@typescript-eslint/parser": "npm:^8.59.4"
|
||||||
lodash: "npm:^4.18.1"
|
lodash: "npm:^4.18.1"
|
||||||
|
typescript: "npm:^5.0.4"
|
||||||
|
vitest: "npm:4.1.5"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: ^10.4.0
|
eslint: ^10.4.0
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
|
|||||||
Reference in New Issue
Block a user