Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -79,7 +79,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 82 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 @@ -275,6 +275,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
40 changes: 12 additions & 28 deletions tests/lib/rules/block-order.js → tests/lib/rules/block-order.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
/**
* @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 { Rule } from '../../../node_modules/@types/eslint'
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
}
})

tester.run('block-order', rule, {
tester.run('block-order', rule as unknown as Rule.RuleModule, {
valid: [
// default
'<script></script><template></template><style></style>',
Expand Down Expand Up @@ -71,44 +72,36 @@ tester.run('block-order', rule, {
// order
{
code: '<script></script><template></template><style></style>',
output: null,
options: [{ order: ['script', 'template', 'style'] }]
},
{
code: '<template></template><script></script><style></style>',
output: null,
options: [{ order: ['template', 'script', 'style'] }]
},
{
code: '<style></style><template></template><script></script>',
output: null,
options: [{ order: ['style', 'template', 'script'] }]
},
{
code: '<template></template><script></script><style></style>',
output: null,
options: [{ order: ['template', 'docs', 'script', 'style'] }]
},
{
code: '<template></template><docs></docs><script></script><style></style>',
output: null,
options: [{ order: ['template', 'script', 'style'] }]
},
{
code: '<docs><div id="id">text <!--comment--> </div><br></docs><script></script><template></template><style></style>',
output: null,
options: [{ order: ['docs', 'script', 'template', 'style'] }]
},
{
code: '<script setup></script><script></script><template></template><style></style>',
output: null,
options: [
{ order: ['script[setup]', 'script:not([setup])', 'template', 'style'] }
]
},
{
code: '<template></template><script setup></script><script></script><style></style>',
output: null,
options: [
{
order: [['script[setup]', 'script:not([setup])', 'template'], 'style']
Expand All @@ -117,24 +110,20 @@ tester.run('block-order', rule, {
},
{
code: '<script></script><script setup></script><template></template><style></style>',
output: null,
options: [{ order: ['script', 'template', 'style'] }]
},
{
code: '<template></template><script></script><script setup></script><style></style>',
output: null,
options: [{ order: [['script', 'template'], 'style'] }]
},
{
code: '<script></script><script setup></script><template></template><style></style>',
output: null,
options: [
{ order: ['script:not([setup])', 'script[setup]', 'template', 'style'] }
]
},
{
code: '<template></template><script></script><script setup></script><style></style>',
output: null,
options: [
{
order: [['script:not([setup])', 'script[setup]', 'template'], 'style']
Expand All @@ -143,7 +132,6 @@ tester.run('block-order', rule, {
},
{
code: '<template></template><script></script><script setup></script><style scoped></style><style></style><i18n locale="ja"></i18n><i18n locale="en"></i18n>',
output: null,
options: [
{
order: [
Expand All @@ -158,7 +146,6 @@ tester.run('block-order', rule, {
},
{
code: '<template></template><script></script><script setup></script><style scoped></style><style></style><i18n locale="en"></i18n><i18n locale="ja"></i18n>',
output: null,
options: [
{
order: [
Expand All @@ -175,17 +162,14 @@ tester.run('block-order', rule, {
},
{
code: '<template></template><docs></docs><script></script><style></style>',
output: null,
options: [{ order: [['docs', 'script', 'template'], 'style'] }]
},
{
code: '<i18n locale="en"></i18n><i18n locale="ja"></i18n>',
output: null,
options: [{ order: ['i18n[locale=en]', 'i18n[locale=ja]'] }]
},
{
code: '<style></style><style scoped></style>',
output: null,
options: [{ order: ['style:not([scoped])', 'style[scoped]'] }]
},

Expand Down
Loading