Skip to content

Commit 38cd2b3

Browse files
authored
feat!: ESM only package (#26)
* feat!: ESM only package * Create new-jars-study.md * fix * fix * fix * Create fifty-eels-poke.md
1 parent e32558c commit 38cd2b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+575
-1535
lines changed

Diff for: .changeset/fifty-eels-poke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intlify/eslint-plugin-svelte": major
3+
---
4+
5+
Drop support legacy config

Diff for: .changeset/new-jars-study.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intlify/eslint-plugin-svelte": major
3+
---
4+
5+
ESM only package

Diff for: .env-cmdrc.cjs

-7
This file was deleted.

Diff for: .env-cmdrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version-ci": {
3+
"IN_VERSION_CI_SCRIPT": "true"
4+
}
5+
}

Diff for: docs/rules/no-raw-text.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ since: v0.0.1
88

99
> disallow to string literal in template
1010
11-
- :star: The `"extends": "plugin:@intlify/svelte/recommended"` or `*.configs["flat/recommended"]` property in a configuration file enables this rule.
11+
- :star: `*.configs.recommended` property in a configuration file enables this rule.
1212

1313
This rule warns the usage of string literal.
1414

Diff for: docs/started.md

+15-155
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ npm install --save-dev eslint @intlify/eslint-plugin-svelte
1717

1818
## :rocket: Usage
1919

20-
### Configuration `eslint.config.[c|m]js`
20+
### Configuration `eslint.config.js`
2121

22-
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.
23-
24-
See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
22+
See also: <https://eslint.org/docs/latest/use/configure/configuration-files>.
2523

2624
Example `eslint.config.js`:
2725

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

3129
export default [
3230
// add more generic rulesets here, such as:
33-
//...eslintPluginSvelte.configs["flat/recommended"],
31+
//...eslintPluginSvelte.configs.recommended,
3432

3533
// Recommended
36-
...intlifySvelte.configs['flat/recommended'],
34+
...intlifySvelte.configs.recommended,
3735
{
3836
rules: {
3937
// override/add rules settings here, such as:
@@ -45,172 +43,34 @@ export default [
4543

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

48-
#### Bundle Configurations `eslint.config.[c|m]js`
46+
#### Bundle Configurations `eslint.config.js`
4947

50-
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.)
48+
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.)
5149

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

5553
### Configuration `.eslintrc.*`
5654

57-
Use the `.eslintrc.*` file to configure rules in ESLint < v9. See also:
58-
https://eslint.org/docs/latest/use/configure/.
59-
60-
Example `.eslintrc.js`:
61-
62-
```js
63-
module.export = {
64-
overrides: [
65-
{
66-
files: ['*.svelte'],
67-
extends: [
68-
// Recommended
69-
'plugin:@intlify/svelte/recommended'
70-
],
71-
rules: {
72-
// Optional.
73-
'@intlify/svelte/no-raw-text': 'error'
74-
// ...
75-
}
76-
}
77-
]
78-
}
79-
```
80-
81-
See [the rule list](./rules/README.md)
82-
83-
#### Bundle Configurations `eslintrc.*`
84-
85-
This plugin provides some predefined configs. You can use the following configs by adding them to `eslintrc.*`.
86-
87-
- `plugin:@intlify/svelte/base`: Settings and rules to enable correct ESlint parsing.
88-
- `plugin:@intlify/svelte/recommended`: Above, plus rules to enforce subjective community defaults to ensure consistency.
89-
90-
::: warning ❗ Attention
91-
92-
The `@intlify/eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
93-
If you are using [eslint-plugin-svelte3] you need to remove it.
94-
95-
```diff
96-
"plugins": [
97-
- "svelte3"
98-
]
99-
```
100-
101-
:::
102-
103-
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3
55+
This plugin no longer supports `.eslintrc.*`.
10456

10557
#### Parser Configuration
10658

107-
If you have specified a parser, you need to configure a parser for `.svelte`.
108-
109-
For example, if you are using the `"@babel/eslint-parser"`, configure it as follows:
59+
If you are using TypeScript, see the documentation for [eslint-plugin-svelte], the official ESLint plugin from Svelte.
11060

111-
```js
112-
module.exports = {
113-
// ...
114-
extends: ['plugin:svelte/recommended'],
115-
// ...
116-
parser: '@babel/eslint-parser',
117-
// Add an `overrides` section to add a parser configuration for svelte.
118-
overrides: [
119-
{
120-
files: ['*.svelte'],
121-
parser: 'svelte-eslint-parser'
122-
}
123-
// ...
124-
]
125-
// ...
126-
}
127-
```
128-
129-
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.
130-
131-
```js
132-
module.exports = {
133-
// ...
134-
extends: ['plugin:svelte/recommended'],
135-
// ...
136-
parser: '@typescript-eslint/parser',
137-
parserOptions: {
138-
// ...
139-
project: 'path/to/your/tsconfig.json',
140-
extraFileExtensions: ['.svelte'] // This is a required setting in `@typescript-eslint/parser` v4.24.0.
141-
},
142-
overrides: [
143-
{
144-
files: ['*.svelte'],
145-
parser: 'svelte-eslint-parser',
146-
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
147-
parserOptions: {
148-
parser: '@typescript-eslint/parser'
149-
}
150-
}
151-
// ...
152-
]
153-
// ...
154-
}
155-
```
156-
157-
If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.
158-
159-
```js
160-
module.exports = {
161-
// ...
162-
overrides: [
163-
{
164-
files: ['*.svelte'],
165-
parser: 'svelte-eslint-parser',
166-
parserOptions: {
167-
parser: {
168-
// Specify a parser for each lang.
169-
ts: '@typescript-eslint/parser',
170-
js: 'espree',
171-
typescript: '@typescript-eslint/parser'
172-
}
173-
}
174-
}
175-
// ...
176-
]
177-
// ...
178-
}
179-
```
61+
<https://sveltejs.github.io/eslint-plugin-svelte/user-guide/#type-script-project>
18062

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

65+
[eslint-plugin-svelte]: https://sveltejs.github.io/eslint-plugin-svelte/
66+
18367
## 🛸 More Plugins
18468

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

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

19074
## :question: FAQ
19175

192-
### What is the "Use the latest svelte-eslint-parser" error?
193-
194-
The most rules of `@intlify/eslint-plugin-svelte` require `svelte-eslint-parser` to check `<template>` ASTs.
195-
196-
Make sure you have one of the following settings in your **.eslintrc**:
197-
198-
- `"extends": ["plugin:@intlify/svelte/recommended"]`
199-
- `"extends": ["plugin:@intlify/svelte/base"]`
200-
201-
<!-- See also: "[Use together with custom parsers](#use-together-with-custom-parsers)" section. -->
202-
203-
### Why doesn't it work on .svelte file?
204-
205-
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`.
206-
207-
```diff
208-
"plugins": [
209-
"@intlify/svelte",
210-
- "svelte3"
211-
]
212-
```
213-
214-
2. Make sure your tool is set to lint `.svelte` files.
215-
216-
- 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`.
76+
TBA

Diff for: lib/configs/base.ts

-9
This file was deleted.

Diff for: lib/configs/flat/base.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/** DON'T EDIT THIS FILE; was created by scripts. */
2-
export = [
2+
import parser from 'svelte-eslint-parser'
3+
import plugin from '../../index.js'
4+
export default [
35
{
46
name: '@intlify/svelte:base:setup',
57
plugins: {
68
get '@intlify/svelte'() {
7-
return require('../../index')
9+
return plugin
810
}
911
}
1012
},
1113
{
1214
name: '@intlify/svelte:base:svelte',
1315
files: ['*.svelte'],
1416
languageOptions: {
15-
parser: require('svelte-eslint-parser')
17+
parser: parser
1618
}
1719
}
1820
]

Diff for: lib/configs/flat/recommended.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** DON'T EDIT THIS FILE; was created by scripts. */
2-
import config from './base'
3-
export = [
2+
import config from './base.js'
3+
export default [
44
...config,
55
{
66
name: '@intlify/svelte:recommended:setup',

Diff for: lib/configs/recommended.ts

-18
This file was deleted.

Diff for: lib/index.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@
22
* @fileoverview ESLint plugin for internationalization with Svelte
33
* @author Yosuke Ota
44
*/
5-
import legacyBase from './configs/base'
6-
import legacyRecommended from './configs/recommended'
7-
import flatBase from './configs/flat/base'
8-
import flatRecommended from './configs/flat/recommended'
9-
import rules from './rules'
10-
import * as meta from './meta'
5+
import flatBase from './configs/flat/base.js'
6+
import flatRecommended from './configs/flat/recommended.js'
7+
import rules from './rules.js'
8+
import * as meta from './meta.js'
119

12-
export = {
13-
meta,
14-
// eslintrc configs
15-
configs: {
16-
base: legacyBase,
17-
recommended: legacyRecommended,
10+
export const configs = {
11+
// flat configs
12+
base: flatBase,
13+
recommended: flatRecommended,
1814

19-
// flat configs
20-
'flat/base': flatBase,
21-
'flat/recommended': flatRecommended
22-
},
23-
rules
15+
// Backward compatibility
16+
'flat/base': flatBase,
17+
'flat/recommended': flatRecommended
2418
}
19+
export { meta, rules }
20+
export default { configs, meta, rules }

Diff for: lib/rules.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** DON'T EDIT THIS FILE; was created by scripts. */
2-
import noRawText from './rules/no-raw-text'
2+
import noRawText from './rules/no-raw-text.js'
33

4-
export = {
4+
export default {
55
'no-raw-text': noRawText
66
}

Diff for: lib/rules/no-raw-text.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44
import type { AST as SvAST } from 'svelte-eslint-parser'
55
import type ESTree from 'estree'
6-
import type { RuleContext, RuleListener } from '../types'
7-
import { defineRule } from '../utils'
6+
import type { RuleContext, RuleListener } from '../types/index.js'
7+
import { defineRule } from '../utils/index.js'
88

99
type LiteralValue = ESTree.Literal['value']
1010
type StaticTemplateLiteral = ESTree.TemplateLiteral & {
@@ -156,7 +156,7 @@ function parseTargetAttrs(
156156
}
157157

158158
function create(context: RuleContext): RuleListener {
159-
const sourceCode = context.getSourceCode()
159+
const sourceCode = context.sourceCode
160160

161161
const config: Config = {
162162
attributes: [],
@@ -252,7 +252,7 @@ function create(context: RuleContext): RuleListener {
252252
}
253253
}
254254

255-
export = defineRule('no-raw-text', {
255+
export default defineRule('no-raw-text', {
256256
meta: {
257257
type: 'suggestion',
258258
docs: {

0 commit comments

Comments
 (0)