Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
],
// turn off some rules from shared configs in all files
rules: {
'eslint-plugin/require-meta-default-options': 'off', // TODO: enable when all rules have defaultOptions

Check warning on line 91 in eslint.config.mjs

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'TODO: enable when all rules have...'
'eslint-plugin/require-meta-docs-recommended': 'off', // use `categories` instead
'eslint-plugin/require-meta-schema-description': 'off',

Expand Down Expand Up @@ -284,6 +284,7 @@
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
'@typescript-eslint/unified-signatures': 'off',
'@typescript-eslint/ban-ts-comment': [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const { ESLint } = require('../../eslint-compat')
const plugin = require('../../../lib/index')
import { ESLint } from '../../eslint-compat'
import plugin from '../../../lib'

describe('eslintrc configs', () => {
for (const name of Object.keys(plugin.configs)) {
Expand Down
103 changes: 51 additions & 52 deletions tests/lib/configs/flat.js → tests/lib/configs/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* @author 唯然<[email protected]>
*/

'use strict'
import { Linter } from 'eslint'
import plugin from '../../../lib'
import { strict as assert } from 'assert'
import { FlatESLint } from '../../eslint-compat'

const plugin = require('../../../lib/index')
const { strict: assert } = require('assert') // node v14 does not support 'assert/strict'
const { FlatESLint } = require('../../eslint-compat')

function mergeConfig(configs) {
let config = { rules: {}, plugins: {} }
function mergeConfig(configs: Linter.FlatConfig[]): Linter.FlatConfig {
let config: Linter.FlatConfig = { rules: {}, plugins: {} }
for (const item of configs) {
config = {
...config,
Expand All @@ -37,16 +36,16 @@ describe('flat configs', () => {
const forVue = mergeConfig(
base.filter((config) => config.files?.includes('*.vue') || !config.files)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.processor, 'vue/vue')
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')

const forOtherThanVue = mergeConfig(
base.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
})
Expand All @@ -61,20 +60,20 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')

const forOtherThanVue = mergeConfig(
essential.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
})
Expand All @@ -89,20 +88,20 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')

const forOtherThanVue = mergeConfig(
stronglyRecommended.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
})
Expand All @@ -117,24 +116,24 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.rules['vue/attributes-order'], 'warn')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.rules!['vue/attributes-order'], 'warn')

const forOtherThanVue = mergeConfig(
recommended.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
assert.strictEqual(forOtherThanVue.rules['vue/attributes-order'], 'warn')
assert.strictEqual(forOtherThanVue.rules!['vue/attributes-order'], 'warn')
})

it('should export vue2-essential config', () => {
Expand All @@ -147,20 +146,20 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')

const forOtherThanVue = mergeConfig(
essential.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
})
Expand All @@ -175,20 +174,20 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')

const forOtherThanVue = mergeConfig(
stronglyRecommended.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
})
Expand All @@ -203,24 +202,24 @@ describe('flat configs', () => {
(config) => config.files?.includes('*.vue') || !config.files
)
)
assert.strictEqual(forVue.plugins.vue, plugin)
assert.strictEqual(forVue.rules['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.rules['vue/attributes-order'], 'warn')
assert.strictEqual(forVue.plugins!.vue, plugin)
assert.strictEqual(forVue.rules!['vue/comment-directive'], 'error')
assert.strictEqual(forVue.rules!['vue/multi-word-component-names'], 'error')
assert.strictEqual(forVue.rules!['vue/attributes-order'], 'warn')

const forOtherThanVue = mergeConfig(
recommended.filter((config) => !config.files?.includes('*.vue'))
)
assert.strictEqual(forOtherThanVue.plugins.vue, plugin)
assert.strictEqual(forOtherThanVue.plugins!.vue, plugin)
assert.strictEqual(
forOtherThanVue.rules['vue/comment-directive'],
forOtherThanVue.rules!['vue/comment-directive'],
undefined
)
assert.strictEqual(
forOtherThanVue.rules['vue/multi-word-component-names'],
forOtherThanVue.rules!['vue/multi-word-component-names'],
'error'
)
assert.strictEqual(forOtherThanVue.rules['vue/attributes-order'], 'warn')
assert.strictEqual(forOtherThanVue.rules!['vue/attributes-order'], 'warn')
})

it('should work the suppress comments with base config', async () => {
Expand Down Expand Up @@ -281,7 +280,7 @@ describe('flat configs', () => {
const result = await eslint.lintText(code, { filePath: 'MyComponent.vue' })

assert.deepStrictEqual(
result[0].messages.map((message) => message.ruleId),
result[0].messages.map((message: Linter.LintMessage) => message.ruleId),
[
'vue/no-parsing-error',
'vue/max-attributes-per-line',
Expand Down
21 changes: 11 additions & 10 deletions tests/lib/rules/block-order.js → tests/lib/rules/block-order.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
/**
* @author Yosuke Ota
*/
'use strict'

const rule = require('../../../lib/rules/block-order')
const RuleTester = require('../../eslint-compat').RuleTester
const assert = require('assert')
const { ESLint } = require('../../eslint-compat')
import assert from 'assert'
import parserVue from 'vue-eslint-parser'
import rule from '../../../lib/rules/block-order'
import { ESLint, RuleTester } from '../../eslint-compat'
import pluginVue from '../../../lib'
import processor from '../../../lib/processor'

// Initialize linter.
const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: {
files: ['**/*.vue'],
languageOptions: {
parser: require('vue-eslint-parser'),
parser: parserVue,
ecmaVersion: 2015
},
plugins: { vue: require('../../../lib/index') },
plugins: { vue: pluginVue },
rules: {
'vue/comment-directive': 'error',
'vue/block-order': 'error'
},
processor: require('../../../lib/processor')
processor
},
fix: true
})

const tester = new RuleTester({
languageOptions: {
parser: require('vue-eslint-parser')
parser: parserVue
}
})

// @ts-expect-error rule ts(#2345)
tester.run('block-order', rule, {
valid: [
// default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@
* @author Toru Nagashima
*/

'use strict'

const assert = require('assert')
const { ESLint } = require('../../eslint-compat')
import assert from 'assert'
import parserVue from 'vue-eslint-parser'
import { ESLint } from '../../eslint-compat'
import pluginVue from '../../../lib'
import processor from '../../../lib/processor'

// Initialize linter.
const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: {
files: ['*.*'],
languageOptions: {
parser: require('vue-eslint-parser'),
parser: parserVue,
ecmaVersion: 2015
},
plugins: { vue: require('../../../lib/index') },
plugins: { vue: pluginVue },
rules: {
'no-unused-vars': 'error',
'vue/comment-directive': 'error',
'vue/no-parsing-error': 'error',
'vue/no-duplicate-attributes': 'error'
},
processor: require('../../../lib/processor')
processor
}
})

async function lintMessages(code) {
async function lintMessages(code: string) {
const result = await eslint.lintText(code, { filePath: 'test.vue' })
return result[0].messages
}
Expand Down Expand Up @@ -357,10 +358,10 @@ describe('comment-directive', () => {
overrideConfig: {
files: ['**/*.vue'],
languageOptions: {
parser: require('vue-eslint-parser'),
parser: parserVue,
ecmaVersion: 2015
},
plugins: { vue: require('../../../lib/index') },
plugins: { vue: pluginVue },
rules: {
'no-unused-vars': 'error',
'vue/comment-directive': [
Expand All @@ -370,11 +371,11 @@ describe('comment-directive', () => {
'vue/no-parsing-error': 'error',
'vue/no-duplicate-attributes': 'error'
},
processor: require('../../../lib/processor')
processor
}
})

async function lintMessages(code) {
async function lintMessages(code: string) {
const result = await eslint.lintText(code, { filePath: 'test.vue' })
return result[0].messages
}
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"module": "node16",
"moduleResolution": "Node16",
"lib": ["es2020"],
"types": [
"vitest/globals"
],
"allowJs": true,
"checkJs": true,
"noEmit": true,
Expand All @@ -25,6 +28,7 @@
},
"include": [
"lib/**/*",
"tests/**/*.ts",
"typings/eslint-plugin-vue/global.d.ts",
"docs/.vitepress/**/*.ts",
"docs/.vitepress/**/*.mts"
Expand Down