Skip to content
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 .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
/tests/fixtures/rules/indent/invalid/ts-v5
/tests/fixtures/rules/valid-compile/invalid/ts
/tests/fixtures/rules/valid-compile/valid/ts
/.svelte-kit
/svelte.config-dist.js
/build
/docs-svelte-kit/shim/eslint.mjs
/docs-svelte-kit/shim/assert.mjs
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ module.exports = {
],
},
overrides: [
{
files: ["*.mjs"],
parserOptions: {
sourceType: "module",
},
},
{
files: ["*.svelte"],
parser: "svelte-eslint-parser",
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/GHPages.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: GHPages

on:
workflow_dispatch: null
push:
branches: [main]

Expand All @@ -12,12 +13,12 @@ jobs:
- uses: actions/setup-node@v2
- name: Install And Build
run: |+
npm install
npm install --legacy-peer-deps
npm run build
npm run docs:build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/.vuepress/dist
publish_dir: ./build
force_orphan: true
2 changes: 1 addition & 1 deletion .github/workflows/NpmPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
registry-url: "https://registry.npmjs.org"
- name: Install Packages
run: npm install
run: npm install --legacy-peer-deps
- name: test and build
run: |
npm run build
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ dist

## repo
/lib
/.svelte-kit
/build
/svelte.config-dist.js
/docs-svelte-kit/shim/eslint.mjs
/docs-svelte-kit/shim/assert.mjs
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.stylelint": true
}
},
"svelte.plugin.typescript.diagnostics.enable": false
}
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`@ota-meshi/eslint-plugin-svelte` is ESLint plugin for Svelte.
It provides many unique check rules by using the template AST.
You can check on the [Online DEMO](https://ota-meshi.github.io/eslint-plugin-svelte/playground/).
You can check on the [Online DEMO](https://ota-meshi.github.io/eslint-plugin-svelte/playground).

::: **_WORKS IN PROGRESS_** :::

Expand Down Expand Up @@ -85,7 +85,7 @@ This plugin provides configs:
- `plugin:@ota-meshi/svelte/base` ... Configuration to enable correct Svelte parsing.
- `plugin:@ota-meshi/svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior.

See [the rule list](https://ota-meshi.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides.
See [the rule list](https://ota-meshi.github.io/eslint-plugin-svelte/rules) to get the `rules` that this plugin provides.

::: warning ❗ Attention

Expand Down Expand Up @@ -247,62 +247,62 @@ These rules relate to possible syntax or logic errors in Svelte code:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/no-dupe-else-if-blocks](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks.html) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
| [@ota-meshi/svelte/no-dynamic-slot-name](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name.html) | disallow dynamic slot name | :star::wrench: |
| [@ota-meshi/svelte/no-not-function-handler](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-not-function-handler.html) | disallow use of not function in event handler | :star: |
| [@ota-meshi/svelte/no-object-in-text-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches.html) | disallow objects in text mustache interpolation | :star: |
| [@ota-meshi/svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile.html) | disallow warnings when compiling. | :star: |
| [@ota-meshi/svelte/no-dupe-else-if-blocks](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
| [@ota-meshi/svelte/no-dynamic-slot-name](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name) | disallow dynamic slot name | :star::wrench: |
| [@ota-meshi/svelte/no-not-function-handler](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-not-function-handler) | disallow use of not function in event handler | :star: |
| [@ota-meshi/svelte/no-object-in-text-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches) | disallow objects in text mustache interpolation | :star: |
| [@ota-meshi/svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile) | disallow warnings when compiling. | :star: |

## Security Vulnerability

These rules relate to security vulnerabilities in Svelte code:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/no-at-html-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-html-tags.html) | disallow use of `{@html}` to prevent XSS attack | :star: |
| [@ota-meshi/svelte/no-target-blank](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-target-blank.html) | disallow `target="_blank"` attribute without `rel="noopener noreferrer"` | |
| [@ota-meshi/svelte/no-at-html-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-html-tags) | disallow use of `{@html}` to prevent XSS attack | :star: |
| [@ota-meshi/svelte/no-target-blank](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-target-blank) | disallow `target="_blank"` attribute without `rel="noopener noreferrer"` | |

## Best Practices

These rules relate to better ways of doing things to help you avoid problems:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/button-has-type](https://ota-meshi.github.io/eslint-plugin-svelte/rules/button-has-type.html) | disallow usage of button without an explicit type attribute | |
| [@ota-meshi/svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags.html) | disallow the use of `{@debug}` | :star: |
| [@ota-meshi/svelte/no-useless-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-useless-mustaches.html) | disallow unnecessary mustache interpolations | :wrench: |
| [@ota-meshi/svelte/button-has-type](https://ota-meshi.github.io/eslint-plugin-svelte/rules/button-has-type) | disallow usage of button without an explicit type attribute | |
| [@ota-meshi/svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags) | disallow the use of `{@debug}` | :star: |
| [@ota-meshi/svelte/no-useless-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-useless-mustaches) | disallow unnecessary mustache interpolations | :wrench: |

## Stylistic Issues

These rules relate to style guidelines, and are therefore quite subjective:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak.html) | enforce the location of first attribute | :wrench: |
| [@ota-meshi/svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes.html) | enforce quotes style of HTML attributes | :wrench: |
| [@ota-meshi/svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent.html) | enforce consistent indentation | :wrench: |
| [@ota-meshi/svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line.html) | enforce the maximum number of attributes per line | :wrench: |
| [@ota-meshi/svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing.html) | enforce unified spacing in mustache | :wrench: |
| [@ota-meshi/svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive.html) | require class directives instead of ternary expressions | :wrench: |
| [@ota-meshi/svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute.html) | enforce use of shorthand syntax in attribute | :wrench: |
| [@ota-meshi/svelte/spaced-html-comment](https://ota-meshi.github.io/eslint-plugin-svelte/rules/spaced-html-comment.html) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |
| [@ota-meshi/svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak) | enforce the location of first attribute | :wrench: |
| [@ota-meshi/svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes) | enforce quotes style of HTML attributes | :wrench: |
| [@ota-meshi/svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent) | enforce consistent indentation | :wrench: |
| [@ota-meshi/svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line) | enforce the maximum number of attributes per line | :wrench: |
| [@ota-meshi/svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing) | enforce unified spacing in mustache | :wrench: |
| [@ota-meshi/svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive) | require class directives instead of ternary expressions | :wrench: |
| [@ota-meshi/svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute) | enforce use of shorthand syntax in attribute | :wrench: |
| [@ota-meshi/svelte/spaced-html-comment](https://ota-meshi.github.io/eslint-plugin-svelte/rules/spaced-html-comment) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |

## Extension Rules

These rules extend the rules provided by ESLint itself to work well in Svelte:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations.html) | disallow variable or `function` declarations in nested blocks | :star: |
| [@ota-meshi/svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations) | disallow variable or `function` declarations in nested blocks | :star: |

## System

These rules relate to this plugin works:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive.html) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system.html) | system rule for working this plugin | :star: |
| [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system) | system rule for working this plugin | :star: |

<!--RULES_TABLE_END-->
<!--RULES_SECTION_END-->
Expand Down
7 changes: 7 additions & 0 deletions docs-svelte-kit/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line no-undef -- ignore
module.exports = {
extends: ["plugin:@ota-meshi/svelte/recommended"],
parserOptions: {
sourceType: "module",
},
}
74 changes: 74 additions & 0 deletions docs-svelte-kit/build-system/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const esbuild = require("esbuild")
const path = require("path")
const fs = require("fs")
// const babelCore = require("@babel/core")
// const t = require("@babel/types")

build(
require.resolve("./src/eslint.mjs"),
path.join(__dirname, "../shim/eslint.mjs"),
["assert"],
)
build(
require.resolve("../../node_modules/assert"),
path.join(__dirname, "../shim/assert.mjs"),
)

/** build */
function build(input, out, injects = []) {
console.log(`build@ ${input}`)
let code = bundle(input, injects)
code = transform(code, injects)
fs.writeFileSync(out, code, "utf8")
}

/** bundle */
function bundle(entryPoint, externals) {
const result = esbuild.buildSync({
entryPoints: [entryPoint],
format: "esm",
bundle: true,
external: ["path", ...externals],
write: false,
})

return `${result.outputFiles[0].text}`
}

/** transform code */
function transform(code, injects) {
// const newCode = babelCore.transformSync(code, {
// babelrc: false,
// plugins: [
// {
// visitor: {
// CallExpression(path) {
// const callee = path.get("callee")
// if (
// callee.type === "Identifier" &&
// callee.node.name === "__require"
// ) {
// callee.replaceWith(t.identifier("__$$$require"))
// }
// },
// },
// },
// ],
// })
return `
${injects
.map((inject) => `import $inject_${inject}$ from '${inject}';`)
.join("\n")}
const $_injects_$ = {${injects
.map((inject) => `${inject}:$inject_${inject}$`)
.join(",\n")}};
const process = {
env: {},
cwd: () => undefined,
}
function require(module, ...args) {
return $_injects_$[module] || {}
}
${code}
`
}
6 changes: 6 additions & 0 deletions docs-svelte-kit/build-system/src/eslint.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint require-jsdoc:0 -- shim */

import * as all from "../../../node_modules/eslint/lib/linter/linter.js"
const Linter = all.Linter
export { Linter }
export default { Linter }
7 changes: 7 additions & 0 deletions docs-svelte-kit/shim/module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint require-jsdoc:0 -- shim */
function createRequire() {
return () => null
}

export { createRequire }
export default { createRequire }
7 changes: 7 additions & 0 deletions docs-svelte-kit/shim/os.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint require-jsdoc:0 -- shim */
function platform() {
return ""
}

export { platform }
export default { platform }
10 changes: 10 additions & 0 deletions docs-svelte-kit/shim/path.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint require-jsdoc:0 -- shim */

function dirname(p) {
return p.split("/").slice(0, -1).join("/") || p
}

const posix = { dirname }
posix.posix = posix
export { dirname, posix }
export default posix
7 changes: 7 additions & 0 deletions docs-svelte-kit/shim/url.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint require-jsdoc:0 -- shim */
function fileURLToPath(p) {
return p
}

export { fileURLToPath }
export default { fileURLToPath }
9 changes: 9 additions & 0 deletions docs-svelte-kit/src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
parserOptions: {
sourceType: "module",
},
rules: {
"node/no-unsupported-features/es-syntax": "off",
"require-jsdoc": "off",
},
}
Loading