{"id":32429381,"url":"https://github.com/mellowco/eslint-config-format","last_synced_at":"2026-04-16T17:33:50.465Z","repository":{"id":48172457,"uuid":"476901585","full_name":"MellowCo/eslint-config-format","owner":"MellowCo","description":"use eslint instead of prettier for code formatting","archived":false,"fork":false,"pushed_at":"2022-07-27T12:07:14.000Z","size":18,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T05:51:30.927Z","etag":null,"topics":["ecmascript","eslint","eslint-plugin","javascript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@meoc/eslint-config-format","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MellowCo.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-02T00:05:16.000Z","updated_at":"2023-06-21T08:37:32.000Z","dependencies_parsed_at":"2022-09-15T18:10:45.255Z","dependency_job_id":null,"html_url":"https://github.com/MellowCo/eslint-config-format","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MellowCo/eslint-config-format","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Feslint-config-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Feslint-config-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Feslint-config-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Feslint-config-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MellowCo","download_url":"https://codeload.github.com/MellowCo/eslint-config-format/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Feslint-config-format/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281019446,"owners_count":26430647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecmascript","eslint","eslint-plugin","javascript"],"created_at":"2025-10-25T20:52:05.317Z","updated_at":"2025-10-25T20:52:24.960Z","avatar_url":"https://github.com/MellowCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @meoc/eslint-config-format\r\n\r\n- 使用eslint取代prettier做代码格式化\r\n- 单引号\r\n- 自动修复格式\r\n- 保证空格一致\r\n- 最大连续空行数2行\r\n\r\n## 用法\r\n\r\n### 下载\r\n``` \r\npnpm add -D eslint @meoc/eslint-config-format\r\n```\r\n\r\n### .eslintrc\r\n```js\r\n{\r\n  \"extends\": \"@meoc/eslint-config-format\"\r\n}\r\n```\r\n\r\n# 规则\r\n## rules\r\n```js\r\n  rules: {\r\n    // 不允许连续空格\r\n    \"no-multi-spaces\": \"error\",\r\n    // 空2格 switch case\r\n    \"indent\": [\"error\", 2, { \"SwitchCase\": 1 }],\r\n    // 对象大括号空格 {   a:b   } =\u003e { a:b }\r\n    \"object-curly-spacing\": [\"error\", \"always\"],\r\n    // 括号去除空格 foo(   'bar'   ) =\u003e  foo('bar');\r\n    \"space-in-parens\": [\"error\", \"never\"],\r\n    // 对象分号前后只有一个空格{ \"foo\"  :    42 } =\u003e { \"foo\": 42 };\r\n    \"key-spacing\": [\"error\", { mode: \"strict\" }],\r\n    // 逗号前后的空格  [1,     2,  3  ,4] =\u003e [1, 2, 4, 4]\r\n    \"comma-spacing\": [\"error\", { \"before\": false, \"after\": true }],\r\n    // 括号内使用空格 [ 1,2   ] =\u003e [ 1,2 ]\r\n    \"array-bracket-spacing\": [\"error\", \"always\"],\r\n    // if else 风格\r\n    \"brace-style\": [\"error\", \"1tbs\"],\r\n    // 函数调用空格 fn  () =\u003e fn()\r\n    \"func-call-spacing\": [\"error\", \"never\"],\r\n    // 函数左括号空格 function name         () {} =\u003e function name(){}\r\n    \"space-before-function-paren\": [\"error\", \"never\"],\r\n    // 语句块的空格 function name() {} =\u003e function name(){}\r\n    \"space-before-blocks\": [\"error\", \"never\"],\r\n    // 关键字前后空格 if  () =\u003e if()\r\n    \"keyword-spacing\": [\"error\", {\r\n      \"overrides\": {\r\n        \"if\": { \"after\": false, before: false },\r\n        \"else\": { \"after\": false, before: false },\r\n      }\r\n    }],\r\n    // 对象取值不能有空格 obj  .  foo =\u003e obj.foo\r\n    \"no-whitespace-before-property\": \"error\",\r\n    // 最大连续空行数\r\n    \"no-multiple-empty-lines\": [\"error\", { \"max\": 2, \"maxEOF\": 1, \"maxBOF\": 0 }],\r\n    // 代码块中去除前后空行\r\n    \"padded-blocks\": [\"error\", \"never\"],\r\n    // ;前后空格 var foo   ;   var bar; =\u003e var foo;var bar;\r\n    \"semi-spacing\": [\"error\", { \"before\": false, \"after\": false }],\r\n    // 操作符是否空格 a=0 =\u003e a = 0\r\n    \"space-infix-ops\": \"error\",\r\n    // 操作符空格 + -\r\n    \"space-unary-ops\": \"error\",\r\n     // 箭头函数空格 ()=\u003e{}  =\u003e () =\u003e {}\r\n    \"arrow-spacing\": [\"error\", { \"before\": true, \"after\": true }],\r\n    // 扩展运算符 {... f} =\u003e {...f}\r\n    \"rest-spread-spacing\": \"error\",\r\n    // 字符串拼接使用模版字符串 'hello' + world =\u003e `hello${world}`\r\n    \"prefer-template\": \"error\",\r\n    // 模版字符串中去除空格 `${ fo  }` =\u003e${fo}\r\n    \"template-curly-spacing\": [\"error\", \"never\"],\r\n    // 链式调用换行\r\n    \"newline-per-chained-call\": [\"error\", { \"ignoreChainWithDepth\": 1 }],\r\n    // 禁止重复模块导入\r\n    \"no-duplicate-imports\": \"error\",\r\n    // 注释各一个 //a =\u003e // a\r\n    \"spaced-comment\": [\"error\", \"always\"],\r\n    // 使用单引号，字符串中包含了一个其它引号 允许\"a string containing 'single' quotes\"\r\n    quotes: [\"error\", \"single\", { \"avoidEscape\": true }]\r\n  },\r\n``` \r\n\r\n## [no-multi-spaces](https://eslint.bootcss.com/docs/rules/no-multi-spaces)\r\n```js\r\n// 不允许连续空格\r\n\"no-multi-spaces\": \"error\",\r\n```\r\n\r\n\u003e 当配置某些空格规则，通常第二个参数，为`never`或`always`\r\n* `never` 表示不需要空格\r\n* `always` 表示需要1个或多个空格\r\n\r\n```js\r\n// 括号内使用空格 [ 1,2   ] =\u003e [ 1,2 ]\r\n\"array-bracket-spacing\": [\"error\", \"always\"],\r\n```\r\n当单独使用`always`时，无法限定好空格的数量，只要空格大于`1`都可以通过`eslint`的校验\r\n```js\r\nconst arr = [1, 2, 3] //false\r\nconst arr = [ 1, 2, 3 ] // true\r\nconst arr = [ 1, 2, 3    ] // true\r\n```\r\n搭配`no-multi-spaces`则可以限定空格的数量为`1`\r\n```js\r\n// 不允许连续空格\r\n\"no-multi-spaces\": \"error\",\r\n// 括号内使用空格 [ 1,2   ] =\u003e [ 1,2 ]\r\n\"array-bracket-spacing\": [\"error\", \"always\"]\r\n\r\nconst arr = [1, 2, 3] //false\r\nconst arr = [ 1, 2, 3    ] // false\r\nconst arr = [ 1, 2, 3 ] // true\r\n```\r\n\r\n## [indent](https://eslint.bootcss.com/docs/rules/indent)\r\n\u003e 使用一致的缩进\r\n```js\r\n // 空2格\r\n \"indent\": [\"error\", 2],\r\n```\r\n\r\n## [object-curly-spacing](https://eslint.bootcss.com/docs/rules/object-curly-spacing)\r\n\u003e 花括号中使用一致的空格\r\n```js\r\n// 对象大括号空格 {   a:b   } =\u003e { a:b }\r\n\"object-curly-spacing\": [\"error\", \"always\"],\r\n```\r\n\r\n## [space-in-parens](https://eslint.bootcss.com/docs/rules/space-in-parens)\r\n\u003e 圆括号内的空格\r\n\r\n```js\r\n// 括号去除空格 foo(   'bar'   ) =\u003e  foo('bar');\r\n\"space-in-parens\": [\"error\", \"never\"],\r\n```\r\n\r\n## [key-spacing](https://eslint.bootcss.com/docs/rules/key-spacing)\r\n\u003e 对象分号前后的空格\r\n第2个参数为对象类型，通过`beforeColon`和`afterColon`设置前后的空格\r\n```js\r\n\"key-spacing\": \r\n[\"error\", { \r\n    \"beforeColon\": false|true, \r\n    \"afterColon\":false|true,\"mode\":\r\n    \"strict\" | \"minimum\"\r\n}]\r\n```\r\n* `\"beforeColon\": false (默认) | true`\r\n    * `false`: 禁止存在空格\r\n    * `true`: 要求至少有一个空格  \r\n* `\"afterColon\": true (默认) | false`\r\n    -   `true`: 要求至少有一个空格\r\n    -   `false`: 禁止存在空格\r\n\r\n- `\"mode\": \"strict\" (默认) | \"minimum\"`\r\n    -   `\"strict\"`: 强制在冒号前后只有一个空格\r\n    -   `\"minimum\"`: 要求在冒号前后最少有一个空格\r\n\r\n```js\r\n// 对象分号前后只有一个空格{ \"foo\"  :    42 } =\u003e { \"foo\": 42 };\r\n\"key-spacing\": [\"error\", { mode: \"strict\" }],\r\n```\r\n\r\n## [comma-spacing](https://eslint.bootcss.com/docs/rules/comma-spacing)\r\n\u003e 逗号(，)周围的空格\r\n通过`before`和`after`，设置前后空格\r\n```js\r\n// 逗号前后去除空格  [1,     2,  3  ,4] =\u003e [1, 2, 3, 4]\r\n\"comma-spacing\": [\"error\", { \"before\": false, \"after\": true }]\r\n```\r\n\r\n## [array-bracket-spacing](https://eslint.bootcss.com/docs/rules/array-bracket-spacing)\r\n\u003e 在方括号[]内使用空格\r\n\r\n```js\r\n\"array-bracket-spacing\": [\"error\", \"always\"],\r\n```\r\n\r\n## [space-infix-ops](https://eslint.bootcss.com/docs/rules/space-infix-ops)\r\n\r\n\u003e 操作符周围空格\r\n```js\r\n // 操作符是否空格 a=0 =\u003e a = 0\r\n \"space-infix-ops\": \"error\",\r\n```\r\n\r\n## [space-unary-ops](https://eslint.bootcss.com/docs/rules/space-unary-ops)\r\n\u003e 一元操作符空格 (`-` `+` `--`  `++`  `!`  `!!`)\r\n```js\r\n// 操作符空格 + -\r\n\"space-unary-ops\": \"error\",\r\n```\r\n\r\n## [brace-style](https://eslint.bootcss.com/docs/rules/brace-style)\r\n\u003e 大括号风格要求\r\n```js\r\nfunction foo()         function foo() {\r\n{                        return true;\r\n  return true;   =\u003e    }    \r\n}                      \r\n\r\n\r\n\r\nif (foo)           if (foo) {\r\n{                     bar();\r\n  bar();   =\u003e      } else {\r\n}                     baz();  \r\n                   }\r\n```\r\n\r\n```js\r\n// if else 风格\r\n\"brace-style\": [\"error\", \"1tbs\"],\r\n```\r\n\r\n## [func-call-spacing](https://eslint.bootcss.com/docs/rules/func-call-spacing)\r\n\u003e 调用函数时的空格\r\n```js\r\n// 函数调用空格 fn   () =\u003e fn()\r\n\"func-call-spacing\": [\"error\", \"never\"],\r\n``` \r\n\r\n## [space-before-function-paren](https://eslint.bootcss.com/docs/rules/space-before-function-paren)\r\n\r\n\u003e 函数左括号空格\r\n\r\n```js\r\n// 函数左括号空格 function name     () {} =\u003e function name(){}\r\n\"space-before-function-paren\": [\"error\", \"never\"],\r\n```\r\n\r\n## [space-before-blocks](https://eslint.bootcss.com/docs/rules/space-before-blocks)\r\n\r\n\u003e 语句块的空格 (简单理解，去除函数右括号空格)\r\n```js\r\n// 语句块的空格 function name()     {} =\u003e function name(){}\r\n\"space-before-blocks\": [\"error\", \"never\"],\r\n```\r\n\r\n## [keyword-spacing](https://eslint.bootcss.com/docs/rules/keyword-spacing)\r\n\u003e 关键字周围空格 (if else from for ...)\r\n```js\r\n\"keyword-spacing\": [\"error\", {\r\n  \"overrides\": {\r\n    \"if\": { \"after\": false, before: false },\r\n    \"else\": { \"after\": false, before: false },\r\n  }\r\n}]\r\n```\r\n## [no-whitespace-before-property](https://eslint.bootcss.com/docs/rules/no-whitespace-before-property)\r\n\u003e 对象取值空格\r\n```js\r\n// 对象取值空格 obj  .  foo =\u003e obj.foo\r\n\"no-whitespace-before-property\": \"error\"\r\n```\r\n\r\n## [no-multiple-empty-lines](https://eslint.bootcss.com/docs/rules/no-multiple-empty-lines)\r\n\u003e 连续空行\r\n* `max` 最大连续空行数\r\n* `maxEOF` 文件末尾的最大连续空行数\r\n* `maxBOF` 文件开始的最大连续空行数\r\n\r\n```js\r\n\"no-multiple-empty-lines\": [\"error\", { \"max\": 2, \"maxEOF\": 1, \"maxBOF\": 0 }],\r\n```\r\n\r\n## [padded-blocks](https://eslint.bootcss.com/docs/rules/padded-blocks)\r\n\u003e 代码块中空行\r\n```js\r\n// 代码块中去除前后空行\r\n\"padded-blocks\": [\"error\", \"never\"],\r\n```\r\n\r\n## [semi-spacing](https://eslint.bootcss.com/docs/rules/semi-spacing)\r\n\u003e 分号前后空格\r\n```js\r\n// 前后空格 var foo   ;   var bar; =\u003e var foo;var bar;\r\n\"semi-spacing\": [\"error\", { \"before\": false, \"after\": false }],\r\n```\r\n\r\n## [arrow-spacing](https://eslint.bootcss.com/docs/rules/arrow-spacing)\r\n\u003e 箭头函数的箭头空格\r\n```js\r\n // 箭头函数空格 ()=\u003e{}  =\u003e () =\u003e {}\r\n\"arrow-spacing\": [\"error\", { \"before\": true, \"after\": true }],\r\n```\r\n\r\n## [rest-spread-spacing](https://eslint.bootcss.com/docs/rules/rest-spread-spacing)\r\n\u003e 扩展运算符(...)空格\r\n```js\r\n// 扩展运算符 {...   f} =\u003e {...f}\r\n\"rest-spread-spacing\": \"error\"\r\n```\r\n\r\n## [prefer-template](https://eslint.bootcss.com/docs/rules/prefer-template)\r\n\u003e 使用模板字面量而非字符串连接\r\n```js\r\n// 字符串拼接使用模版字符串 'hello' + world =\u003e `hello${world}`\r\n\"prefer-template\": \"error\",\r\n```\r\n\r\n## [template-curly-spacing](https://eslint.bootcss.com/docs/rules/template-curly-spacing)\r\n\u003e 模板字符串中空格\r\n```js\r\n// 模版字符串中去除空格 `${ fo  }` =\u003e${fo}\r\n\"template-curly-spacing\": [\"error\", \"never\"],\r\n```\r\n\r\n## [newline-per-chained-call](https://eslint.bootcss.com/docs/rules/newline-per-chained-call)\r\n\u003e 链式调用换行\r\n```js\r\n// 链式调用换行\r\n// _.chain({}).map(foo).filter(bar).value();\r\n\r\n// _\r\n// .chain({})\r\n// .map(foo)\r\n// .filter(bar)\r\n// .value();\r\n\r\n\"newline-per-chained-call\": [\"error\", { \"ignoreChainWithDepth\": 1 }],\r\n```\r\n\r\n## [no-duplicate-imports](https://eslint.bootcss.com/docs/rules/no-duplicate-imports)\r\n\u003e 禁止重复导入\r\n```js\r\n// 禁止重复模块导入\r\n\"no-duplicate-imports\": \"error\",\r\n```\r\n\r\n## [spaced-comment](https://eslint.bootcss.com/docs/rules/spaced-comment)\r\n\u003e 注释前有空白\r\n```js\r\n // 注释空格 //a =\u003e // a\r\n \"spaced-comment\": [\"error\", \"always\"],\r\n```\r\n\r\n## [quotes](https://eslint.bootcss.com/docs/rules/quotes)\r\n\u003e 单引号\r\n```js\r\n// 使用单引号，字符串中包含了一个其它引号 允许\"a string containing 'single' quotes\"\r\nquotes: [\"error\", \"single\", { \"avoidEscape\": true }]\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmellowco%2Feslint-config-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmellowco%2Feslint-config-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmellowco%2Feslint-config-format/lists"}