diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 000000000..dbd194153 --- /dev/null +++ b/.browserslistrc @@ -0,0 +1 @@ +extends @1stg/browserslist-config/modern diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 000000000..e5b6d8d6a --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 000000000..12520636c --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://unpkg.com/@changesets/config/schema.json", + "changelog": [ + "@changesets/changelog-github", + { + "repo": "ota-meshi/eslint-plugin-svelte" + } + ], + "commit": false, + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json new file mode 100644 index 000000000..6589ed1ca --- /dev/null +++ b/.codesandbox/ci.json @@ -0,0 +1,4 @@ +{ + "node": "16", + "sandboxes": [] +} diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 000000000..0a81ca47f --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "@1stg" +} diff --git a/.eslintignore b/.eslintignore index 688687940..2a12d04a4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -16,3 +16,4 @@ /build /docs-svelte-kit/shim/eslint.mjs /docs-svelte-kit/shim/assert.mjs +!/.*.js diff --git a/.eslintrc.js b/.eslintrc.js index 57826c457..69840b3ff 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -35,6 +35,13 @@ module.exports = { ], }, overrides: [ + { + files: ["*.md"], + extends: "plugin:mdx/recommended", + settings: { + "mdx/code-blocks": true, + }, + }, { files: ["*.mjs"], parserOptions: { diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 3972ed6c5..53a761d1b 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -53,3 +53,5 @@ jobs: run: yarn install --ignore-engines - name: Test run: yarn test + - name: Type Coverage + run: yarn typecov diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 000000000..41d279b30 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + + - name: Setup Node.js 16 + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Install Dependencies + run: yarn + + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 + with: + # This expects you to have a script called release which does a build for your packages and calls changeset publish + publish: yarn release + commit: "chore: release eslint-plugin-svelte" + title: "chore: release eslint-plugin-svelte" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 14f844ab3..abaddc83f 100644 --- a/.gitignore +++ b/.gitignore @@ -104,6 +104,7 @@ dist /yarn.lock /lib /.svelte-kit +/.type-coverage /build /svelte.config-dist.js /docs-svelte-kit/shim/eslint.mjs diff --git a/.remarkrc.json b/.remarkrc.json new file mode 100644 index 000000000..7b1cf04ab --- /dev/null +++ b/.remarkrc.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "@1stg/remark-config", + ["lint-final-definition", false], + ["lint-no-shortcut-reference-link", false] + ] +} diff --git a/.stylelintignore b/.stylelintignore new file mode 100644 index 000000000..e0a593652 --- /dev/null +++ b/.stylelintignore @@ -0,0 +1,15 @@ +.*ignore +.npmrc +LICENSE +*.png +*.json +*.lock +*.log +*.svg +*.yaml +*.yml +/tests/fixtures/rules +# TODO: enable the following +# should we ignore markdown files? +*.md +/docs-svelte-kit/ diff --git a/README.md b/README.md index 9ce2a1594..596f71ac1 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ You can check on the [Online DEMO](https://ota-meshi.github.io/eslint-plugin-sve [![NPM downloads](https://img.shields.io/npm/dt/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![Build Status](https://github.com/ota-meshi/eslint-plugin-svelte/workflows/CI/badge.svg?branch=main)](https://github.com/ota-meshi/eslint-plugin-svelte/actions?query=workflow%3ACI) +[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/ota-meshi/eslint-plugin-svelte.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ota-meshi/eslint-plugin-svelte/context:javascript) +[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fota-meshi%2Feslint-plugin-svelte%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage) +[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org) +[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) +[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets) + ## :name_badge: What is this plugin? [ESLint] plugin for [Svelte]. @@ -61,7 +67,7 @@ npm install --save-dev eslint eslint-plugin-svelte svelte ### Configuration -Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/user-guide/configuring](https://eslint.org/docs/user-guide/configuring). +Use `.eslintrc.*` file to configure rules. See also: . Example **.eslintrc.js**: @@ -176,7 +182,7 @@ module.exports = { } ``` -See also [https://github.com/ota-meshi/svelte-eslint-parser#readme](https://github.com/ota-meshi/svelte-eslint-parser#readme). +See also . #### settings.svelte @@ -242,6 +248,7 @@ Example **.vscode/settings.json**: ## :white_check_mark: Rules + :wrench: Indicates that the rule is fixable, and using `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the reported problems. @@ -330,6 +337,7 @@ These rules relate to this plugin works: + diff --git a/docs/README.md b/docs/README.md index f20a36a5b..ca56969b0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,6 +17,12 @@ You can check on the [Online DEMO](./playground.md). [![NPM downloads](https://img.shields.io/npm/dt/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![Build Status](https://github.com/ota-meshi/eslint-plugin-svelte/workflows/CI/badge.svg?branch=main)](https://github.com/ota-meshi/eslint-plugin-svelte/actions?query=workflow%3ACI) +[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/ota-meshi/eslint-plugin-svelte.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ota-meshi/eslint-plugin-svelte/context:javascript) +[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fota-meshi%2Feslint-plugin-svelte%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage) +[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org) +[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) +[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets) + ## :name_badge: What is this plugin? [ESLint] plugin for [Svelte]. @@ -41,7 +47,9 @@ See [User Guide](./user-guide.md). ## :white_check_mark: Rules + See [Available Rules](./rules.md). + ## :lock: License diff --git a/docs/rules/first-attribute-linebreak.md b/docs/rules/first-attribute-linebreak.md index b7d02de0a..81bff0f0a 100644 --- a/docs/rules/first-attribute-linebreak.md +++ b/docs/rules/first-attribute-linebreak.md @@ -19,6 +19,7 @@ This rule aims to enforce a consistent location for the first attribute. + ```svelte diff --git a/docs/rules/no-reactive-functions.md b/docs/rules/no-reactive-functions.md index 8bd4f26b4..cc41e68cc 100644 --- a/docs/rules/no-reactive-functions.md +++ b/docs/rules/no-reactive-functions.md @@ -25,12 +25,20 @@ This rule reports whenever a function is defined in a reactive statement. This i /* eslint svelte/no-reactive-functions: "error" */ /* ✓ GOOD */ - const arrowFn = () => { /* ... */ } - const func = function() { /* ... */ } - + const arrowFn = () => { + /* ... */ + } + const func = function () { + /* ... */ + } + /* ✗ BAD */ - $: arrowFn = () => { /* ... */ } - $: func = function() { /* ... */ } + $: arrowFn = () => { + /* ... */ + } + $: func = function () { + /* ... */ + } ``` @@ -46,6 +54,7 @@ This rule was taken from [@tivac/eslint-plugin-svelte]. This rule is compatible with `@tivac/svelte/reactive-functions` rule. [@tivac/eslint-plugin-svelte]: https://github.com/tivac/eslint-plugin-svelte/ + ## :rocket: Version This rule was introduced in eslint-plugin-svelte v2.5.0 diff --git a/docs/rules/prefer-style-directive.md b/docs/rules/prefer-style-directive.md index bb369ebf9..73199c1c0 100644 --- a/docs/rules/prefer-style-directive.md +++ b/docs/rules/prefer-style-directive.md @@ -21,6 +21,7 @@ Style directive were added in Svelte v3.46. + ```svelte diff --git a/docs/rules/shorthand-attribute.md b/docs/rules/shorthand-attribute.md index 67f3114ee..87a4edd9a 100644 --- a/docs/rules/shorthand-attribute.md +++ b/docs/rules/shorthand-attribute.md @@ -19,6 +19,7 @@ This rule enforces the use of the shorthand syntax in attribute. + ```svelte diff --git a/docs/rules/shorthand-directive.md b/docs/rules/shorthand-directive.md index f05cfb691..105ff4385 100644 --- a/docs/rules/shorthand-directive.md +++ b/docs/rules/shorthand-directive.md @@ -19,6 +19,7 @@ This rule enforces the use of the shorthand syntax in directives. + ```svelte diff --git a/docs/rules/spaced-html-comment.md b/docs/rules/spaced-html-comment.md index 2cb62edce..d3ea66654 100644 --- a/docs/rules/spaced-html-comment.md +++ b/docs/rules/spaced-html-comment.md @@ -48,7 +48,7 @@ You cannot enforce this style by using [prettier-plugin-svelte]. That is, this r ``` - `"always"` ... There must be at least one whitespace after ``. -- `"never"` ... There should be no leading or trailing whitespace.  There should be no whitespace following. +- `"never"` ... There should be no leading or trailing whitespace. There should be no whitespace following. ## :rocket: Version diff --git a/docs/user-guide.md b/docs/user-guide.md index ba7fe2a5c..d5a971ab5 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -19,7 +19,7 @@ npm install --save-dev eslint eslint-plugin-svelte svelte ### Configuration -Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/user-guide/configuring](https://eslint.org/docs/user-guide/configuring). +Use `.eslintrc.*` file to configure rules. See also: . Example **.eslintrc.js**: @@ -134,7 +134,7 @@ module.exports = { } ``` -See also [https://github.com/ota-meshi/svelte-eslint-parser#readme](https://github.com/ota-meshi/svelte-eslint-parser#readme). +See also . #### settings.svelte diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 000000000..98b832316 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,3 @@ +"use strict" + +module.exports = require("@1stg/lint-staged/tsc") diff --git a/package.json b/package.json index 3f1467cee..709751d6a 100644 --- a/package.json +++ b/package.json @@ -36,16 +36,21 @@ "docs:watch": "yarn svelte-kit dev", "eslint-fix": "eslint . --fix", "format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs --fix", - "lint": "eslint .", + "lint": "run-p lint:*", + "lint:es": "eslint --cache -f friendly .", + "lint:style": "stylelint --cache .", "mocha": "yarn ts ./node_modules/mocha/bin/mocha.js", "new": "yarn ts ./tools/new-rule.ts", "prebuild": "yarn clean", - "prepublishOnly": "yarn clean && yarn build", - "pretest:base": "cross-env DEBUG=eslint-plugin-svelte*", - "preversion": "yarn test && git add .", + "prepare": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0", + "prerelease": "yarn clean && yarn build", + "pretest": "yarn build", + "release": "changeset publish", "svelte-kit": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/vite/bin/vite.js", "test": "yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000", + "test:debug": "cross-env DEBUG=eslint-plugin-svelte* yarn test", "ts": "node -r esbuild-register", + "typecov": "type-coverage", "update": "yarn ts ./tools/update.ts && yarn format-for-gen-file", "version": "env-cmd -e version yarn update && git add ." }, @@ -69,10 +74,18 @@ "svelte-eslint-parser": "^0.18.0" }, "devDependencies": { + "@1stg/browserslist-config": "^1.2.3", + "@1stg/commitlint-config": "^3.1.4", + "@1stg/lint-staged": "^3.3.0", + "@1stg/remark-config": "^4.0.3", + "@1stg/simple-git-hooks": "^0.2.1", + "@1stg/stylelint-config": "^4.6.1", "@babel/core": "^7.16.0", "@babel/eslint-parser": "^7.17.0", "@babel/plugin-proposal-function-bind": "^7.16.7", "@babel/types": "^7.16.0", + "@changesets/changelog-github": "^0.4.6", + "@changesets/cli": "^2.24.2", "@fontsource/fira-mono": "^4.5.0", "@ota-meshi/eslint-plugin": "^0.11.3", "@sindresorhus/slugify": "^2.1.0", @@ -99,17 +112,21 @@ "@typescript-eslint/parser": "^5.4.1-0", "@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@4", "assert": "^2.0.0", + "commitlint": "^17.0.3", + "cross-env": "^7.0.3", "env-cmd": "^10.1.0", "esbuild": "^0.15.0", "esbuild-register": "^3.2.0", "escape-html": "^1.0.3", "eslint": "^8.0.0", "eslint-config-prettier": "^8.3.0", + "eslint-formatter-friendly": "^7.0.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-plugin": "^5.0.0", "eslint-plugin-json-schema-validator": "^4.0.0", "eslint-plugin-jsonc": "^2.0.0", "eslint-plugin-markdown": "^3.0.0", + "eslint-plugin-mdx": "^2.0.2", "eslint-plugin-node": "^11.1.0", "eslint-plugin-node-dependencies": "^0.9.0", "eslint-plugin-prettier": "^4.0.0", @@ -119,12 +136,14 @@ "eslint-scope": "^7.1.1", "estree-walker": "^3.0.0", "less": "^4.1.2", + "lint-staged": "^13.0.3", "locate-character": "^2.0.5", "magic-string": "^0.26.0", "markdown-it-anchor": "^8.4.1", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.0", "mocha": "^10.0.0", + "npm-run-all": "^4.1.5", "nyc": "^15.1.0", "pako": "^2.0.3", "postcss-nested": "^5.0.6", @@ -135,17 +154,31 @@ "prismjs": "^1.25.0", "sass": "^1.51.0", "semver": "^7.3.5", + "simple-git-hooks": "^2.8.0", "stylelint": "^14.0.0", "stylelint-config-standard": "^27.0.0", "stylus": "^0.58.0", "svelte": "^3.46.1", "svelte-adapter-ghpages": "0.0.2", + "type-coverage": "^2.22.0", "typescript": "^4.5.2", "vite": "^3.0.0-0", "vite-plugin-svelte-md": "^0.1.5", - "yaml": "^2.1.1" + "yaml": "^2.1.1", + "yarn-deduplicate": "^5.0.0" }, "publishConfig": { "access": "public" + }, + "typeCoverage": { + "atLeast": 98.62, + "cache": true, + "detail": true, + "ignoreAsAssertion": true, + "ignoreNested": true, + "ignoreNonNullAssertion": true, + "showRelativePath": true, + "strict": true, + "update": true } } diff --git a/simple-git-hooks.js b/simple-git-hooks.js new file mode 100644 index 000000000..589ebaef0 --- /dev/null +++ b/simple-git-hooks.js @@ -0,0 +1,3 @@ +"use strict" + +module.exports = require("@1stg/simple-git-hooks") diff --git a/stylelint.config.js b/stylelint.config.js new file mode 100644 index 000000000..11b495e8b --- /dev/null +++ b/stylelint.config.js @@ -0,0 +1,5 @@ +"use strict" + +module.exports = { + extends: "@1stg/stylelint-config", +} diff --git a/tests/fixtures/rules/indent/valid/pug01-input.svelte b/tests/fixtures/rules/indent/valid/pug01-input.svelte index b420dca98..446e2556c 100644 --- a/tests/fixtures/rules/indent/valid/pug01-input.svelte +++ b/tests/fixtures/rules/indent/valid/pug01-input.svelte @@ -3,8 +3,8 @@ diff --git a/tests/utils/source-code-fixer.ts b/tests/utils/source-code-fixer.ts index 41f36ba40..15234ff33 100644 --- a/tests/utils/source-code-fixer.ts +++ b/tests/utils/source-code-fixer.ts @@ -86,7 +86,7 @@ export function applyFixes( } // clone the array - const remainingMessages = [] + const remainingMessages: M[] = [] const fixes: (HasFixMessage & M)[] = [] const bom = sourceText.startsWith(BOM) ? BOM : "" const text = bom ? sourceText.slice(1) : sourceText @@ -105,7 +105,7 @@ export function applyFixes( // Remain it as a problem if it's overlapped or it's a negative range if (lastPos >= start || start > end) { - remainingMessages.push(problem) + remainingMessages.push(problem as M) return false } diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index ca5807a88..7ab27c2e7 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -224,9 +224,6 @@ function writeFixtures( })) : null, })), - { - quotingType: '"', - }, )}`, "utf8", ) diff --git a/tools/update-readme.ts b/tools/update-readme.ts index ce6145a6b..66e1be17a 100644 --- a/tools/update-readme.ts +++ b/tools/update-readme.ts @@ -81,7 +81,8 @@ fs.writeFileSync( ) .replace( /\(https:\/\/ota-meshi.github.io\/eslint-plugin-svelte(.*?)\)/gu, - (_s, c: string) => `(.${c.endsWith("/") ? c.slice(0, -1) : c}.md)`, + (_s: string, c: string) => + `(.${c.endsWith("/") ? c.slice(0, -1) : c}.md)`, ), "utf8", )