

{a} + {b} = {a + b + c}
- - - -{@html a}
-{@debug a} - - - - - - -{a} + {b} = {a + b+c}
- - - -{@html a}
-{@debug a} - - - - - - -diff --git a/.browserslistrc b/.browserslistrc deleted file mode 100644 index dbd194153..000000000 --- a/.browserslistrc +++ /dev/null @@ -1 +0,0 @@ -extends @1stg/browserslist-config/modern diff --git a/.github/workflows/GHPages.yml b/.github/workflows/GHPages.yml index 30ccd714c..d002776e9 100644 --- a/.github/workflows/GHPages.yml +++ b/.github/workflows/GHPages.yml @@ -28,18 +28,20 @@ jobs: - uses: pnpm/action-setup@v2 - uses: actions/setup-node@v4 - name: Install And Build - run: |+ + run: | pnpm install + cd packages/eslint-plugin-svelte pnpm run update - pnpm run build + pnpm build + cd ../../docs-svelte-kit export NODE_OPTIONS="--max-old-space-size=8192" - pnpm run docs:build + pnpm build - name: Setup Pages uses: actions/configure-pages@v5 - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: ./build/eslint-plugin-svelte + path: ./docs-svelte-kit/build/eslint-plugin-svelte - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 206d2d01b..0c82d3a9f 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [main] +env: + project_root_path: ./packages/eslint-plugin-svelte + jobs: lint: runs-on: ubuntu-latest @@ -15,12 +18,20 @@ jobs: - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install - - name: Lint - run: |+ + - name: Lint eslint-plugin-svelte + run: | pnpm run build pnpm run lint + working-directory: ${{ env.project_root_path }} + - name: Lint docs-svelte-kit + run: | + pnpm run build + pnpm run lint + working-directory: ./docs-svelte-kit - name: Type Coverage run: pnpm run typecov + working-directory: ${{ env.project_root_path }} + build: runs-on: ubuntu-latest steps: @@ -30,9 +41,11 @@ jobs: - name: Install Packages run: pnpm install - name: Build - run: |+ + run: | pnpm run update pnpm run build + working-directory: ${{ env.project_root_path }} + test: name: 'Test for ESLint ${{ matrix.eslint }} on Node.js: ${{ matrix.node }} OS: ${{matrix.os}}' runs-on: ${{ matrix.os }} @@ -49,15 +62,23 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - - name: Install ESLint ${{ matrix.eslint }} - run: |+ - pnpm install -D eslint@${{ matrix.eslint }} - rm -rf node_modules - if: matrix.eslint != 9 - name: Install Packages run: pnpm install + - name: Build eslint-plugin-svelte + run: pnpm build + working-directory: ${{ env.project_root_path }} + # Hack: Install `eslint-plugin-svelte` is necessary for `packages/eslint-plugin-svelte/tests/src/configs` tests. + - name: Install eslint-plugin-svelte + run: pnpm install -D eslint-plugin-svelte + working-directory: ${{ env.project_root_path }} + - name: Install ESLint ${{ matrix.eslint }} + if: matrix.eslint != 9 + run: pnpm install -D -w eslint@${{ matrix.eslint }} + - name: Test - run: pnpm run test + run: pnpm test + working-directory: ${{ env.project_root_path }} + test-for-svelte-v4: name: 'Test for Svelte v4 on Node.js: ${{ matrix.node }} OS: ${{matrix.os}}' runs-on: ${{ matrix.os }} @@ -65,7 +86,7 @@ jobs: matrix: os: [ubuntu-latest] eslint: [9] - node: [18, 20] + node: [18, 20, 22] include: # On old Node.js version - eslint: 8 @@ -83,17 +104,20 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install svelte@4 - run: |+ + run: | pnpm install -D svelte@4 rm -rf node_modules + working-directory: ${{ env.project_root_path }} - name: Install ESLint ${{ matrix.eslint }} - run: |+ - pnpm install -D eslint@${{ matrix.eslint }} + run: | + pnpm install -D -w eslint@${{ matrix.eslint }} rm -rf node_modules - name: Install Packages run: pnpm install - name: Test run: pnpm run test + working-directory: ${{ env.project_root_path }} + test-for-svelte-v3: name: Test for Svelte v3 runs-on: ${{ matrix.os }} @@ -109,18 +133,25 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - - name: Remove @sveltejs/kit # Remove @sveltejs/kit because postinstall fails on old node. - run: |+ - pnpm rm @sveltejs/kit - rm -rf node_modules - name: Install svelte@3 - run: |+ - pnpm install -D svelte@3 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 eslint@8 + # Remove @sveltejs/kit because postinstall fails on old node. + run: | + cd docs-svelte-kit + pnpm rm @sveltejs/kit + cd .. + pnpm install -D -w @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 eslint@8 + cd packages/eslint-plugin-svelte + pnpm install -D svelte@3 + cd ../.. + rm -rf packages/eslint-plugin-svelte/node_modules + rm -rf docs-svelte-kit/node_modules rm -rf node_modules - name: Install Packages run: pnpm install - name: Test run: pnpm run test + working-directory: ${{ env.project_root_path }} + test-for-typescript-eslint-v5: name: Test for typescript-eslint v5 runs-on: ${{ matrix.os }} @@ -137,13 +168,15 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install typescript-eslint v5 - run: |+ - pnpm install -D @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 + run: | + pnpm install -D -w @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 rm -rf node_modules - name: Install Packages run: pnpm install - name: Test run: pnpm run test + working-directory: ${{ env.project_root_path }} + update-resources: runs-on: ubuntu-latest steps: @@ -156,6 +189,7 @@ jobs: run: pnpm install - name: Update resources run: pnpm run update + working-directory: ${{ env.project_root_path }} - name: Check changes run: | git add --all && \ diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 84140fb47..000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: 👔 Format - -on: - workflow_dispatch: null - -permissions: - contents: write - -jobs: - format: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 - - uses: actions/setup-node@v4 - - name: Install deps - run: pnpm install -f - - name: Format - run: pnpm run lint-fix - - name: Commit - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - - git add . - if [ -z "$(git status --porcelain)" ]; then - echo "no formatting changed" - exit 0 - fi - git commit -m "chore: format" - git push - echo "pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)" diff --git a/.gitignore b/.gitignore index 3e278fe25..cf1b233b1 100644 --- a/.gitignore +++ b/.gitignore @@ -102,12 +102,14 @@ dist ## repo /pnpm-lock.yaml -/lib -/.svelte-kit -/.type-coverage -/build +packages/eslint-plugin-svelte/lib +packages/eslint-plugin-svelte/.type-coverage + +docs-svelte-kit/.svelte-kit +docs-svelte-kit/build /svelte.config-dist.js /docs-svelte-kit/shim/eslint.mjs /docs-svelte-kit/shim/assert.mjs /docs-svelte-kit/src/routes/*.md /docs-svelte-kit/src/routes/**/*.md +packages/eslint-plugin-svelte/README.md diff --git a/.stylelintignore b/.stylelintignore deleted file mode 100644 index 04f08797f..000000000 --- a/.stylelintignore +++ /dev/null @@ -1,22 +0,0 @@ -.*ignore -.npmrc -LICENSE -*.png -*.json -*.js -*.mjs -*.ts -*.mts -*.tsx -*.lock -*.log -*.svg -*.yaml -*.yml -/tests/fixtures/rules -# TODO: enable the following -# should we ignore markdown files? -*.md -/docs-svelte-kit/ -/coverage -/build diff --git a/README.md b/README.md index 435777a47..9a6c25600 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,36 @@ for some context. ::: +#### Specify `svelte.config.js` + +If you are using `eslint.config.js`, we recommend that you import and specify `svelte.config.js`. +By specifying it, some rules of `eslint-plugin-svelte` will read it and try to behave well for you by default. +Some Svelte configurations will be statically loaded from `svelte.config.js` even if you don't specify it, but you need to specify it to make it work better. + +Example **eslint.config.js**: + +```js +import eslintPluginSvelte from 'eslint-plugin-svelte'; +import svelteConfig from './svelte.config.js'; +export default [ + ...eslintPluginSvelte.configs['flat/recommended'], + { + files: [ + '**/*.svelte', + '*.svelte' + // Add more files if you need. + // '**/*.svelte.ts', '*.svelte.ts', '**/*.svelte.js', '*.svelte.js', + ], + languageOptions: { + parserOptions: { + // Specify the `svelte.config.js`. + svelteConfig + } + } + } +]; +``` + #### settings.svelte You can change the behavior of this plugin with some settings. @@ -274,6 +304,12 @@ Specifies options for Svelte compile. Effects rules that use Svelte compile. The #### settings.svelte.kit +::: warning + +Even if you don't specify `settings.svelte.kit`, the rules will try to load information from `svelte.config.js`, so specify `settings.svelte.kit` if the default doesn't work. + +::: + If you use SvelteKit with not default configuration, you need to set below configurations. The schema is subset of SvelteKit's configuration. Therefore please check [SvelteKit docs](https://kit.svelte.dev/docs/configuration) for more details. @@ -385,6 +421,7 @@ These rules relate to better ways of doing things to help you avoid problems: | [svelte/no-inline-styles](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-inline-styles/) | disallow attributes and directives that produce inline styles | | | [svelte/no-reactive-functions](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-functions/) | it's not necessary to define functions in reactive statements | :bulb: | | [svelte/no-reactive-literals](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-literals/) | don't assign literal values in reactive statements | :bulb: | +| [svelte/no-svelte-internal](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/) | svelte/internal will be removed in Svelte 6. | | | [svelte/no-unused-class-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-class-name/) | disallow the use of a class in the template without a corresponding style | | | [svelte/no-unused-svelte-ignore](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: | | [svelte/no-useless-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: | diff --git a/docs-svelte-kit/build-system/build.mts b/docs-svelte-kit/build-system/build.ts similarity index 94% rename from docs-svelte-kit/build-system/build.mts rename to docs-svelte-kit/build-system/build.ts index e13936dbb..c2ff84359 100644 --- a/docs-svelte-kit/build-system/build.mts +++ b/docs-svelte-kit/build-system/build.ts @@ -5,7 +5,7 @@ import { fileURLToPath } from 'url'; const dirname = path.dirname(fileURLToPath(import.meta.url)); -build(path.join(dirname, '../../node_modules/assert'), path.join(dirname, '../shim/assert.mjs')); +build(path.join(dirname, '../node_modules/assert'), path.join(dirname, '../shim/assert.mjs')); /** build */ function build(input: string, out: string, injects: string[] = []) { diff --git a/docs-svelte-kit/eslint.config.mjs b/docs-svelte-kit/eslint.config.mjs new file mode 100644 index 000000000..5e336f604 --- /dev/null +++ b/docs-svelte-kit/eslint.config.mjs @@ -0,0 +1,59 @@ +import * as myPlugin from '@ota-meshi/eslint-plugin'; +import globals from 'globals'; + +/** + * @type {import('eslint').Linter.FlatConfig[]} + */ +const config = [ + { + ignores: [ + 'node_modules/', + '.svelte-kit/', + 'build/', + 'shim/eslint.mjs', + 'shim/assert.mjs', + 'src/routes/*.md', + 'src/routes/**/*.md', + 'src/app.html' + ] + }, + ...myPlugin.config({ + eslintPlugin: true, + ts: true, + json: true, + packageJson: true, + yaml: true, + md: true, + prettier: true, + svelte: { withTs: false } + }), + { + languageOptions: { + sourceType: 'module', + globals: { + ...globals.browser, + require: 'readonly' + } + } + }, + { + rules: { + 'jsdoc/require-jsdoc': 'off', + '@typescript-eslint/no-shadow': 'off', + 'no-shadow': 'off', + '@typescript-eslint/naming-convention': 'off', + 'new-cap': 'off', + complexity: 'off', + 'n/no-missing-import': 'off', + 'n/file-extension-in-import': 'off', + 'n/no-extraneous-import': 'off' + } + }, + { + files: ['**/*.svelte'], + languageOptions: { + parserOptions: { project: null } + } + } +]; +export default config; diff --git a/docs-svelte-kit/package.json b/docs-svelte-kit/package.json new file mode 100644 index 000000000..6f776212a --- /dev/null +++ b/docs-svelte-kit/package.json @@ -0,0 +1,63 @@ +{ + "name": "docs", + "private": true, + "type": "module", + "scripts": { + "lint": "eslint --cache .", + "lint-fix": "eslint --cache . --fix", + "build": "cd ../packages/eslint-plugin-svelte && pnpm build && cd ../../docs-svelte-kit && pnpm run svelte-kit build", + "preview": "pnpm run svelte-kit preview", + "dev": "pnpm run svelte-kit dev", + "svelte-kit": "vite" + }, + "devDependencies": { + "@babel/core": "^7.24.5", + "@babel/types": "^7.24.5", + "@fontsource/fira-mono": "^5.0.13", + "@ota-meshi/eslint-plugin": "^0.17.1", + "@sindresorhus/slugify": "^2.2.1", + "@sveltejs/adapter-static": "^3.0.1", + "@sveltejs/kit": "^2.5.9", + "@sveltejs/vite-plugin-svelte": "^3.1.0", + "@types/babel__core": "^7.20.5", + "@types/cross-spawn": "^6.0.6", + "@types/escape-html": "^1.0.4", + "@types/eslint-scope": "^3.7.7", + "@types/eslint-visitor-keys": "^3.3.0", + "@types/less": "^3.0.6", + "@types/markdown-it": "^14.1.1", + "@types/markdown-it-container": "^2.0.10", + "@types/markdown-it-emoji": "^3.0.1", + "@types/node": "^20.12.12", + "@types/prismjs": "^1.26.4", + "@types/stylus": "^0.48.42", + "@typescript/vfs": "^1.5.0", + "acorn": "^8.11.3", + "assert": "^2.1.0", + "cross-spawn": "^7.0.3", + "env-cmd": "^10.1.0", + "esbuild": "^0.21.3", + "escape-html": "^1.0.3", + "eslint-plugin-svelte": "workspace:^", + "eslint-scope": "^8.0.1", + "eslint-visitor-keys": "^4.0.0", + "espree": "^10.0.1", + "globals": "^15.2.0", + "markdown-it-anchor": "^9.0.0", + "markdown-it-container": "^4.0.0", + "markdown-it-emoji": "^3.0.0", + "pako": "^2.1.0", + "postcss-nested": "^6.0.1", + "prism-svelte": "^0.5.0", + "prismjs": "^1.29.0", + "sass": "^1.77.2", + "source-map-js": "^1.2.0", + "stylus": "^0.63.0", + "svelte": "^5.0.0-next.112", + "svelte-adapter-ghpages": "0.2.2", + "util": "^0.12.5", + "vite": "^5.2.11", + "vite-plugin-eslint4b": "^0.4.2", + "vite-plugin-svelte-md": "^0.1.7" + } +} diff --git a/docs-svelte-kit/shim/source-map-js.mjs b/docs-svelte-kit/shim/source-map-js.mjs index 86bbf5794..4bdafa563 100644 --- a/docs-svelte-kit/shim/source-map-js.mjs +++ b/docs-svelte-kit/shim/source-map-js.mjs @@ -1,4 +1,4 @@ -import { SourceMapGenerator } from '../../node_modules/source-map-js/lib/source-map-generator.js'; -import { SourceMapConsumer } from '../../node_modules/source-map-js/lib/source-map-consumer.js'; +import { SourceMapGenerator } from '../node_modules/source-map-js/lib/source-map-generator.js'; +import { SourceMapConsumer } from '../node_modules/source-map-js/lib/source-map-consumer.js'; export { SourceMapGenerator, SourceMapConsumer }; export default { SourceMapGenerator, SourceMapConsumer }; diff --git a/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte b/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte index 393070fc5..72d0e18c8 100644 --- a/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte +++ b/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte @@ -3,7 +3,7 @@ import ESLintEditor from '../eslint/ESLintEditor.svelte'; import { preprocess, postprocess, createLinterConfig } from '../eslint/scripts/linter.js'; import { loadTsParser } from '../eslint/scripts/ts-parser.js'; - import { loadModulesForBrowser } from '../../../../src/utils/load-module'; + import { loadModulesForBrowser } from '../../../../packages/eslint-plugin-svelte/src/utils/load-module.ts'; import { Linter } from 'eslint'; import globals from 'globals'; diff --git a/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte b/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte index 21c85cec6..ce705f0af 100644 --- a/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte +++ b/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte @@ -10,7 +10,7 @@ createLinterConfig } from '../eslint/scripts/linter.js'; import { loadTsParser } from '../eslint/scripts/ts-parser.js'; - import { loadModulesForBrowser } from '../../../../src/utils/load-module'; + import { loadModulesForBrowser } from '../../../../packages/eslint-plugin-svelte/src/utils/load-module.ts'; import { Linter } from 'eslint'; import globals from 'globals'; let tsParser = null; @@ -190,10 +190,9 @@
{a} + {b} = {a + b + c}
- - - -{@html a}
-{@debug a} - - - - - - -{a} + {b} = {a + b+c}
- - - -{@html a}
-{@debug a} - - - - - - -