Skip to content

feat!: ESM only package #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/fifty-eels-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-svelte": major
---

Drop support legacy config
5 changes: 5 additions & 0 deletions .changeset/new-jars-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-svelte": major
---

ESM only package
7 changes: 0 additions & 7 deletions .env-cmdrc.cjs

This file was deleted.

5 changes: 5 additions & 0 deletions .env-cmdrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version-ci": {
"IN_VERSION_CI_SCRIPT": "true"
}
}
2 changes: 1 addition & 1 deletion docs/rules/no-raw-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ since: v0.0.1

> disallow to string literal in template

- :star: The `"extends": "plugin:@intlify/svelte/recommended"` or `*.configs["flat/recommended"]` property in a configuration file enables this rule.
- :star: `*.configs.recommended` property in a configuration file enables this rule.

This rule warns the usage of string literal.

Expand Down
170 changes: 15 additions & 155 deletions docs/started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ npm install --save-dev eslint @intlify/eslint-plugin-svelte

## :rocket: Usage

### Configuration `eslint.config.[c|m]js`
### Configuration `eslint.config.js`

In ESLint v9, the the default way to configure files is using an `eslint.config.[c|m]js` file, but this can be used starting from ESLint v8.57.0.

See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
See also: <https://eslint.org/docs/latest/use/configure/configuration-files>.

Example `eslint.config.js`:

Expand All @@ -30,10 +28,10 @@ import intlifySvelte from '@intlify/eslint-plugin-svelte'

export default [
// add more generic rulesets here, such as:
//...eslintPluginSvelte.configs["flat/recommended"],
//...eslintPluginSvelte.configs.recommended,

// Recommended
...intlifySvelte.configs['flat/recommended'],
...intlifySvelte.configs.recommended,
{
rules: {
// override/add rules settings here, such as:
Expand All @@ -45,172 +43,34 @@ export default [

See [the rule list](./rules/README.md)

#### Bundle Configurations `eslint.config.[c|m]js`
#### Bundle Configurations `eslint.config.js`

This plugin provides some predefined configs. You can use the following configs by adding them to `eslint.config.[c|m]js`. (All flat configs in this plugin are provided as arrays, so spread syntax is required when combining them with other configs.)
This plugin provides some predefined configs. You can use the following configs by adding them to `eslint.config.js`. (All configs in this plugin are provided as arrays, so spread syntax is required when combining them with other configs.)

- `*configs["flat/base"]`: Settings and rules to enable correct ESlint parsing.
- `*configs["flat/recommended"]`: Above, plus rules to enforce subjective community defaults to ensure consistency.
- `*.configs.base`: Settings and rules to enable correct ESlint parsing.
- `*.configs.recommended`: Above, plus rules to enforce subjective community defaults to ensure consistency.

### Configuration `.eslintrc.*`

Use the `.eslintrc.*` file to configure rules in ESLint < v9. See also:
https://eslint.org/docs/latest/use/configure/.

Example `.eslintrc.js`:

```js
module.export = {
overrides: [
{
files: ['*.svelte'],
extends: [
// Recommended
'plugin:@intlify/svelte/recommended'
],
rules: {
// Optional.
'@intlify/svelte/no-raw-text': 'error'
// ...
}
}
]
}
```

See [the rule list](./rules/README.md)

#### Bundle Configurations `eslintrc.*`

This plugin provides some predefined configs. You can use the following configs by adding them to `eslintrc.*`.

- `plugin:@intlify/svelte/base`: Settings and rules to enable correct ESlint parsing.
- `plugin:@intlify/svelte/recommended`: Above, plus rules to enforce subjective community defaults to ensure consistency.

::: warning ❗ Attention

The `@intlify/eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
If you are using [eslint-plugin-svelte3] you need to remove it.

```diff
"plugins": [
- "svelte3"
]
```

:::

[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3
This plugin no longer supports `.eslintrc.*`.

#### Parser Configuration

If you have specified a parser, you need to configure a parser for `.svelte`.

For example, if you are using the `"@babel/eslint-parser"`, configure it as follows:
If you are using TypeScript, see the documentation for [eslint-plugin-svelte], the official ESLint plugin from Svelte.

```js
module.exports = {
// ...
extends: ['plugin:svelte/recommended'],
// ...
parser: '@babel/eslint-parser',
// Add an `overrides` section to add a parser configuration for svelte.
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser'
}
// ...
]
// ...
}
```

For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.

```js
module.exports = {
// ...
extends: ['plugin:svelte/recommended'],
// ...
parser: '@typescript-eslint/parser',
parserOptions: {
// ...
project: 'path/to/your/tsconfig.json',
extraFileExtensions: ['.svelte'] // This is a required setting in `@typescript-eslint/parser` v4.24.0.
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
// ...
]
// ...
}
```

If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.

```js
module.exports = {
// ...
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: {
// Specify a parser for each lang.
ts: '@typescript-eslint/parser',
js: 'espree',
typescript: '@typescript-eslint/parser'
}
}
}
// ...
]
// ...
}
```
<https://sveltejs.github.io/eslint-plugin-svelte/user-guide/#type-script-project>

See also <https://github.com/sveltejs/svelte-eslint-parser#readme>.

[eslint-plugin-svelte]: https://sveltejs.github.io/eslint-plugin-svelte/

## 🛸 More Plugins

### [eslint-plugin-svelte](https://sveltejs.github.io/eslint-plugin-svelte/)
### [eslint-plugin-svelte]

ESLint plugin for Svelte compatible with `@intlify/eslint-plugin-svelte`.
Use it if you want ESLint to do more checks on your Svelte files.

## :question: FAQ

### What is the "Use the latest svelte-eslint-parser" error?

The most rules of `@intlify/eslint-plugin-svelte` require `svelte-eslint-parser` to check `<template>` ASTs.

Make sure you have one of the following settings in your **.eslintrc**:

- `"extends": ["plugin:@intlify/svelte/recommended"]`
- `"extends": ["plugin:@intlify/svelte/base"]`

<!-- See also: "[Use together with custom parsers](#use-together-with-custom-parsers)" section. -->

### Why doesn't it work on .svelte file?

1. Make sure you don't have `eslint-plugin-svelte3` in your config. The `eslint-plugin-svelte3` extracts the content from `<script>` tags, but `@intlify/eslint-plugin-svelte` requires `<script>` tags and other element tags in order to distinguish template and script in `*.svelte`.

```diff
"plugins": [
"@intlify/svelte",
- "svelte3"
]
```

2. Make sure your tool is set to lint `.svelte` files.

- CLI targets only `.js` files by default. You have to specify additional extensions by `--ext` option or glob patterns. E.g. `eslint "src/**/*.{js,svelte}"` or `eslint src --ext .svelte`.
TBA
9 changes: 0 additions & 9 deletions lib/configs/base.ts

This file was deleted.

8 changes: 5 additions & 3 deletions lib/configs/flat/base.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/** DON'T EDIT THIS FILE; was created by scripts. */
export = [
import parser from 'svelte-eslint-parser'
import plugin from '../../index.js'
export default [
{
name: '@intlify/svelte:base:setup',
plugins: {
get '@intlify/svelte'() {
return require('../../index')
return plugin
}
}
},
{
name: '@intlify/svelte:base:svelte',
files: ['*.svelte'],
languageOptions: {
parser: require('svelte-eslint-parser')
parser: parser
}
}
]
4 changes: 2 additions & 2 deletions lib/configs/flat/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** DON'T EDIT THIS FILE; was created by scripts. */
import config from './base'
export = [
import config from './base.js'
export default [
...config,
{
name: '@intlify/svelte:recommended:setup',
Expand Down
18 changes: 0 additions & 18 deletions lib/configs/recommended.ts

This file was deleted.

30 changes: 13 additions & 17 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
* @fileoverview ESLint plugin for internationalization with Svelte
* @author Yosuke Ota
*/
import legacyBase from './configs/base'
import legacyRecommended from './configs/recommended'
import flatBase from './configs/flat/base'
import flatRecommended from './configs/flat/recommended'
import rules from './rules'
import * as meta from './meta'
import flatBase from './configs/flat/base.js'
import flatRecommended from './configs/flat/recommended.js'
import rules from './rules.js'
import * as meta from './meta.js'

export = {
meta,
// eslintrc configs
configs: {
base: legacyBase,
recommended: legacyRecommended,
export const configs = {
// flat configs
base: flatBase,
recommended: flatRecommended,

// flat configs
'flat/base': flatBase,
'flat/recommended': flatRecommended
},
rules
// Backward compatibility
'flat/base': flatBase,
'flat/recommended': flatRecommended
}
export { meta, rules }
export default { configs, meta, rules }
4 changes: 2 additions & 2 deletions lib/rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** DON'T EDIT THIS FILE; was created by scripts. */
import noRawText from './rules/no-raw-text'
import noRawText from './rules/no-raw-text.js'

export = {
export default {
'no-raw-text': noRawText
}
8 changes: 4 additions & 4 deletions lib/rules/no-raw-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import type { AST as SvAST } from 'svelte-eslint-parser'
import type ESTree from 'estree'
import type { RuleContext, RuleListener } from '../types'
import { defineRule } from '../utils'
import type { RuleContext, RuleListener } from '../types/index.js'
import { defineRule } from '../utils/index.js'

type LiteralValue = ESTree.Literal['value']
type StaticTemplateLiteral = ESTree.TemplateLiteral & {
Expand Down Expand Up @@ -156,7 +156,7 @@ function parseTargetAttrs(
}

function create(context: RuleContext): RuleListener {
const sourceCode = context.getSourceCode()
const sourceCode = context.sourceCode

const config: Config = {
attributes: [],
Expand Down Expand Up @@ -252,7 +252,7 @@ function create(context: RuleContext): RuleListener {
}
}

export = defineRule('no-raw-text', {
export default defineRule('no-raw-text', {
meta: {
type: 'suggestion',
docs: {
Expand Down
Loading