Initial commit

This commit is contained in:
Romein van Buren 2023-07-27 21:56:03 +02:00
commit 251589f71d
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
14 changed files with 5111 additions and 0 deletions

17
.eslintrc.js Normal file
View File

@ -0,0 +1,17 @@
'use strict';
const svelteConfig = require('./configs/svelte.js');
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: './configs/node.js',
ignorePatterns: [ '/example/wrong.*' ],
overrides: [ {
files: [ './example/correct.svelte' ],
overrides: svelteConfig.overrides,
parserOptions: svelteConfig.parserOptions,
env: svelteConfig.env,
extends: svelteConfig.extends,
plugins: svelteConfig.plugins,
} ],
};

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
.DS_Store

7
LICENSE.md Normal file
View File

@ -0,0 +1,7 @@
Copyright (c) 2023 Romein van Buren
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

61
README.md Normal file
View File

@ -0,0 +1,61 @@
# yeslint!
A sensible, modern collection of configuration files for [ESLint] that enforces beautiful code. It contains both rules to ensure correct code (e.g. enforce `break` statements in each `switch` `case`), and rules to make your code beautiful (e.g. adding a trailing comma to array items that start on a newline).
## What's included
Currently, the 3 following configuration files are available:
* `generic`: generic ESLint configuration for all modern JavaScript runtimes.
* `node`: an extension on the generic config, with rules specific to Node.js.
* `svelte`: configuration for [Svelte] and JavaScript in browser environments.
## Examples
Please see [the `examples` directory](./examples) for some examples. Files that start with `wrong.` contain many errors, and the fixed version of those files is in their `correct.` equivalent.
## Installation
Install it together with ESLint using [npm], [pnpm], [Yarn], or whatever package manager you like to use:
```bash
npm install --save-dev eslint yeslint
```
```bash
yarn add --dev eslint yeslint
```
```bash
pnpm add --save-dev eslint yeslint
```
Then, tell ESLint to extend this configuration. Add it either in `.eslintrc.json`, add it as the default export in `.eslintrc.js`, or add it in your `package.json` under the `"eslintConfig"` key.
Please consider the following example. You should replace `<name>` with the name of the configuration you want to use.
```javascript
module.exports = {
extends: './node_modules/yeslint/config/<name>.js',
};
```
Or add this to your `package.json` file:
```json
"eslintConfig": {
"extends": "./node_modules/yeslint/config/<name>.js"
}
```
After installing, run `npx eslint .` to lint your code for the first time, or use `npx eslint --fix .` to lint while automatically fixing all auto-fixable problems ESLint finds in your codebase.
## Author & license
© [Romein van Buren](mailto:romein@vburen.nl) 2023. yeslint! is released under the MIT license — see LICENSE for the full license text.
[ESLint]: https://eslint.org/
[Svelte]: https://svelte.dev/
[npm]: https://www.npmjs.com/
[pnpm]: https://pnpm.io/
[Yarn]: https://yarnpkg.com/

202
configs/generic.js Normal file
View File

@ -0,0 +1,202 @@
'use strict';
/**
* Generic ESLint configuration for all modern JavaScript runtimes.
*
* @package yeslint!
* @author Romein van Buren
* @license MIT
* @type {import('eslint').Linter.Config}
*/
const generic = {
parserOptions: {
ecmaVersion: 2021,
},
env: {
es6: true,
},
extends: [ 'eslint:recommended' ],
plugins: [ 'import' ],
rules: {
'no-undef': [
'error',
{
typeof: true,
},
],
'require-atomic-updates': 0,
indent: [
'error',
2,
{ SwitchCase: 1 },
],
strict: [
'error',
'safe',
],
quotes: [
'error',
'single',
],
semi: [
'warn',
'always',
],
'accessor-pairs': 'error',
'array-bracket-spacing': [
'error',
'always',
],
'array-element-newline': [ 'warn' ],
'array-bracket-newline': [
'warn',
{ minItems: 2 },
],
'arrow-body-style': [
'error',
'as-needed',
{ requireReturnForObjectLiteral: true },
],
'arrow-parens': [
'error',
'as-needed',
],
'arrow-spacing': 'error',
'block-spacing': [
'error',
'always',
],
'comma-dangle': [
'warn',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'never',
exports: 'never',
functions: 'never',
},
],
'comma-spacing': 'error',
'comma-style': [
'error',
'last',
],
'computed-property-spacing': [
'error',
'never',
],
'generator-star-spacing': 'error',
'id-blacklist': 'error',
'id-match': 'error',
'jsx-quotes': 'error',
'keyword-spacing': 'error',
'key-spacing': [
'warn',
{
beforeColon: false,
},
],
'linebreak-style': [
'error',
'unix',
],
'no-unused-vars': 'warn',
'no-alert': 'error',
'no-caller': 'error',
'no-confusing-arrow': [
'error',
{ allowParens: true },
],
'no-console': 'off',
'no-div-regex': 'error',
'no-duplicate-imports': 'error',
'import/extensions': [
'warn',
'ignorePackages',
],
'no-extend-native': 'error',
'no-extra-label': 'error',
'no-fallthrough': 'off',
'no-floating-decimal': 'error',
'no-implicit-coercion': [
'error',
{
boolean: false,
number: false,
string: false,
},
],
'no-inner-declarations': [
'error',
'functions',
],
'no-iterator': 'error',
'no-label-var': 'error',
'no-lone-blocks': 'error',
'no-new-object': 'error',
'no-new-require': 'error',
'no-new-wrappers': 'error',
'no-restricted-globals': [
'error',
'event',
'name',
],
'no-restricted-imports': 'error',
'no-restricted-modules': 'error',
'no-restricted-syntax': 'error',
'no-script-url': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow-restricted-names': 'error',
'no-spaced-func': 'error',
'no-trailing-spaces': 'error',
'no-unmodified-loop-condition': 'error',
'no-useless-constructor': 'error',
'no-whitespace-before-property': 'error',
'no-with': 'error',
'object-curly-spacing': [
'error',
'always',
],
'object-shorthand': [
'error',
'properties',
],
'quote-props': [
'error',
'as-needed',
],
'prefer-const': 'error',
'require-yield': 'error',
'semi-spacing': [ 'error' ],
'space-before-blocks': 'error',
'space-before-function-paren': [
'error',
'never',
],
'space-in-parens': [
'error',
'never',
],
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'template-curly-spacing': 'error',
curly: 2,
'brace-style': [
'error',
'stroustrup',
],
'wrap-iife': [
'error',
'any',
],
'yield-star-spacing': 'error',
'multiline-ternary': [
'error',
'never',
],
'no-nested-ternary': 'error',
},
};
module.exports = generic;

25
configs/node.js Normal file
View File

@ -0,0 +1,25 @@
'use strict';
const generic = require('./generic.js');
/**
* An extension on the default yeslint! generic config, with rules specific to
* Node.js environments.
*
* @package yeslint!
* @author Romein van Buren
* @license MIT
* @type {import('eslint').Linter.Config}
*/
const node = {
parserOptions: { ...generic.parserOptions },
env: {
...generic.env,
node: true,
},
extends: [ ...generic.extends ],
plugins: [ ...generic.plugins ],
rules: { ...generic.rules },
};
module.exports = node;

100
configs/svelte.js Normal file
View File

@ -0,0 +1,100 @@
'use strict';
const generic = require('./generic.js');
/**
* An extension on the default yeslint! generic config, with rules specific to
* Svelte codebases and JavaScript source code for browser environments.
*
* @package yeslint!
* @author Romein van Buren
* @license MIT
* @type {import('eslint').Linter.Config}
*/
const svelte = {
parserOptions: {
...generic.parserOptions,
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
...generic.browser,
browser: true,
node: true,
es6: true,
},
extends: [
...generic.extends,
'plugin:svelte/recommended',
],
plugins: [
...generic.plugins,
'svelte',
],
overrides: [ {
files: '*.svelte',
parser: 'svelte-eslint-parser',
rules: {
'no-inner-declarations': 0,
'svelte/no-inner-declarations': [
'error',
'functions',
],
'svelte/html-quotes': [
'error',
{
prefer: 'double',
dynamic: {
quoted: false,
avoidInvalidUnquotedInHTML: false,
},
},
],
'svelte/no-useless-mustaches': 'warn',
'svelte/require-store-reactive-access': 'warn',
'svelte/no-reactive-literals': 'error',
'svelte/html-closing-bracket-spacing': 'warn',
'svelte/indent': [
'warn',
{
indent: 2,
ignoredNodes: [],
switchCase: 1,
alignAttributesVertically: false,
},
],
'svelte/max-attributes-per-line': [
'warn',
{
multiline: 1,
singleline: 4,
},
],
'svelte/first-attribute-linebreak': [
'warn',
{
multiline: 'below',
singleline: 'beside',
},
],
'svelte/mustache-spacing': 'warn',
'svelte/no-extra-reactive-curlies': 'error',
'svelte/no-spaces-around-equal-signs-in-attribute': 'warn',
'svelte/prefer-class-directive': 'warn',
'svelte/shorthand-attribute': 'warn',
'svelte/shorthand-directive': 'warn',
'svelte/spaced-html-comment': 'warn',
'svelte/no-at-html-tags': 0,
'svelte/html-self-closing': [
'warn',
'all',
],
},
} ],
rules: {
...generic.rules,
strict: 0,
},
};
module.exports = svelte;

14
example/correct.js Normal file
View File

@ -0,0 +1,14 @@
'use strict';
module.exports = {
properties: 'This is not ugly, the whitespace is perfect, and the quotes are single',
object: { spacing: 'required!' },
functions: [
env => console.log(env.password),
function({ password }) {
console.log(password);
},
],
};

17
example/correct.svelte Normal file
View File

@ -0,0 +1,17 @@
<script>
const anotherObject = {
properties: 'This is not ugly, the whitespace is perfect, and the quotes are single',
object: { spacing: 'required!' },
functions: [
env => console.log(env.password),
function({ password }) {
console.log(password);
},
],
};
</script>
<div class={anotherObject.className} />

9
example/wrong.js Normal file
View File

@ -0,0 +1,9 @@
'why not use strict?';
module.exports = {
"properties" : `This is ugly, the whitespace is too much, and the backticks are unnecessary`,
object:{spacing:'required!'},
functions: [( env )=> console.log(env.password),function ({password}) { console.log( password )}]
}

15
example/wrong.svelte Normal file
View File

@ -0,0 +1,15 @@
<script>
export let property // unused
const anotherObject ={
"properties" : `This is ugly, the whitespace is too much, and the backticks are unnecessary`,
object:{spacing:'required!'},
functions: [( env )=> console.log(env.password),function ({password}) { console.log( password )}]
};
</script>
<div class="{anotherObject.className}"></div>

23
index.js Normal file
View File

@ -0,0 +1,23 @@
'use strict';
/**
* yeslint!
*
* A sensible, modern collection of configuration files for ESLint that enforces
* beautiful code. It contains both rules to ensure correct code (e.g. enforce
* `break` statements in each `switch` `case`), and rules to make your code
* beautiful (e.g. adding a trailing comma to array items that start on a
* newline).
*
* This object re-exports the individual configuration files in the `config`
* folder from a central palce.
*
* @package yeslint!
* @author Romein van Buren
* @license MIT
*/
module.exports = {
generic: require('./configs/generic.js'),
node: require('./configs/node.js'),
svelte: require('./configs/svelte.js'),
};

4576
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

43
package.json Normal file
View File

@ -0,0 +1,43 @@
{
"name": "yeslint",
"version": "1.0.0",
"description": "Sensible configuration for your ESLint installation",
"main": "index.js",
"author": "Romein van Buren <romein@vburen.nl>",
"homepage": "https://github.com/garraflavatra/yeslint#readme",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/garraflavatra/yeslint.git"
},
"keywords": [
"lint",
"linting",
"linter",
"ESLint"
],
"bugs": {
"url": "https://github.com/garraflavatra/yeslint/issues"
},
"files": [
"index.js",
"configs"
],
"dependencies": {
"eslint-plugin-import": "^2.27.5"
},
"peerDependencies": {
"eslint": "^7.9.0 || ^8.0.0",
"eslint-plugin-svelte": "^2.32.4"
},
"peerDependenciesMeta": {
"eslint-plugin-svelte": {
"optional": true
}
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-plugin-svelte": "^2.32.4",
"svelte": "^4.1.1"
}
}