Skip to content

Commit

Permalink
chore: tidy up eslint config (#9468)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Aug 1, 2022
1 parent 22084a6 commit f4addcf
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 46 deletions.
62 changes: 37 additions & 25 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ module.exports = defineConfig({
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts']
}
],
'node/no-restricted-require': [
'error',
Object.keys(require('./packages/vite/package.json').devDependencies).map(
(d) => ({
name: d,
message:
`devDependencies can only be imported using ESM syntax so ` +
`that they are included in the rollup bundle. If you are trying to ` +
`lazy load a dependency, use (await import('dependency')).default instead.`
})
)
],
'node/no-extraneous-import': [
'error',
{
Expand Down Expand Up @@ -107,6 +95,30 @@ module.exports = defineConfig({
]
},
overrides: [
{
files: ['packages/**'],
excludedFiles: '**/__tests__/**',
rules: {
'no-restricted-globals': ['error', 'require', '__dirname', '__filename']
}
},
{
files: 'packages/vite/**/*.*',
rules: {
'node/no-restricted-require': [
'error',
Object.keys(
require('./packages/vite/package.json').devDependencies
).map((d) => ({
name: d,
message:
`devDependencies can only be imported using ESM syntax so ` +
`that they are included in the rollup bundle. If you are trying to ` +
`lazy load a dependency, use (await import('dependency')).default instead.`
}))
]
}
},
{
files: ['packages/vite/src/node/**'],
rules: {
Expand All @@ -120,9 +132,11 @@ module.exports = defineConfig({
}
},
{
files: ['packages/plugin-*/**/*'],
files: ['packages/create-vite/template-*/**', '**/build.config.ts'],
rules: {
'no-restricted-globals': ['error', 'require', '__dirname', '__filename']
'no-undef': 'off',
'node/no-missing-import': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
},
{
Expand All @@ -132,7 +146,6 @@ module.exports = defineConfig({
'node/no-extraneous-require': 'off',
'node/no-missing-import': 'off',
'node/no-missing-require': 'off',
'no-undef': 'off',
// engine field doesn't exist in playgrounds
'node/no-unsupported-features/es-builtins': [
'error',
Expand All @@ -145,17 +158,22 @@ module.exports = defineConfig({
{
version: '^14.18.0 || >=16.0.0'
}
]
],
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
},
{
files: ['packages/create-vite/template-*/**', '**/build.config.ts'],
files: ['playground/**'],
excludedFiles: '**/__tests__/**',
rules: {
'node/no-missing-import': 'off'
'no-undef': 'off',
'no-empty': 'off',
'no-constant-condition': 'off',
'@typescript-eslint/no-empty-function': 'off'
}
},
{
files: ['playground/**', '*.js'],
files: ['*.js'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
Expand All @@ -165,12 +183,6 @@ module.exports = defineConfig({
rules: {
'@typescript-eslint/triple-slash-reference': 'off'
}
},
{
files: 'packages/vite/**/*.*',
rules: {
'no-restricted-globals': ['error', 'require', '__dirname', '__filename']
}
}
],
reportUnusedDisableDirectives: true
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"preinstall": "npx only-allow pnpm",
"postinstall": "simple-git-hooks",
"format": "prettier --write --cache .",
"lint": "eslint --cache packages/*/{src,types,__tests__}/** playground/**/__tests__/**/*.ts scripts/**/*.ts",
"lint": "eslint --cache .",
"typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit",
"test": "run-s test-unit test-serve test-build",
"test-serve": "vitest run -c vitest.config.e2e.ts",
Expand Down Expand Up @@ -65,7 +65,7 @@
"cross-env": "^7.0.3",
"esbuild": "^0.14.47",
"eslint": "^8.20.0",
"eslint-define-config": "^1.5.1",
"eslint-define-config": "^1.6.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^6.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-lit-ts/src/my-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, css, LitElement } from 'lit'
import { LitElement, css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import litLogo from './assets/lit.svg'

Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-lit/src/my-element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, css, LitElement } from 'lit'
import { LitElement, css, html } from 'lit'
import litLogo from './assets/lit.svg'

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MagicString from 'magic-string'
import colors from 'picocolors'
import fg from 'fast-glob'
import { sync as resolve } from 'resolve'
import type { Plugin } from 'rollup'
import type { Plugin, RollupOptions } from 'rollup'
import { defineConfig } from 'rollup'
import pkg from './package.json'

Expand Down Expand Up @@ -185,7 +185,7 @@ function createCjsConfig(isProduction: boolean) {
})
}

export default (commandLineArgs: any) => {
export default (commandLineArgs: any): RollupOptions[] => {
const isDev = commandLineArgs.watch
const isProduction = !isDev

Expand Down
1 change: 1 addition & 0 deletions playground/css/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ text('.charset-css', charset)
import './dep.css'
import './glob-dep.css'

// eslint-disable-next-line import/order
import { barModuleClasses } from 'css-js-dep'
document
.querySelector('.css-js-dep-module')
Expand Down
2 changes: 1 addition & 1 deletion playground/css/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module.exports = {
}

const fs = require('fs')
const glob = require('fast-glob')
const path = require('path')
const glob = require('fast-glob')
const { normalizePath } = require('vite')

/**
Expand Down
3 changes: 1 addition & 2 deletions playground/json/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ async function createServer(
/**
* @type {import('vite').ViteDevServer}
*/
let vite
vite = await require('vite').createServer({
const vite = await require('vite').createServer({
root,
logLevel: isTest ? 'error' : 'info',
server: {
Expand Down
1 change: 1 addition & 0 deletions playground/resolve/browser-field/relative.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-duplicates */
import ra from './no-ext'
import rb from './no-ext.js' // no substitution
import rc from './ext'
Expand Down
10 changes: 5 additions & 5 deletions playground/tailwind/__test__/tailwind.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
isBuild,
browserLogs,
editFile,
untilUpdated,
getColor,
getBgColor,
browserLogs,
page
getColor,
isBuild,
page,
untilUpdated
} from '~utils'

test('should render', async () => {
Expand Down
2 changes: 1 addition & 1 deletion playground/tailwind/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebHistory, createRouter } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'
import Page from './views/Page.vue'

const history = createWebHistory()
Expand Down
1 change: 0 additions & 1 deletion playground/wasm/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import init from './add.wasm?init'
init().then(({ exports }) => {
// eslint-disable-next-line no-undef
self.postMessage({ result: exports.add(1, 2) })
})
2 changes: 1 addition & 1 deletion playground/worker/my-worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { msg as msgFromDep } from 'dep-to-optimize'
import { mode, msg } from './modules/workerImport'
import { bundleWithPlugin } from './modules/test-plugin'
import { msg as msgFromDep } from 'dep-to-optimize'

self.onmessage = (e) => {
if (e.data === 'ping') {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4addcf

Please sign in to comment.