惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
D
DataBreaches.Net
P
Proofpoint News Feed
小众软件
小众软件
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
雷峰网
雷峰网
G
Google Developers Blog

szhshp 的第三边境研究所

假设, AI 把我代替的那一刻真的到来 | szhshp 的第三边境研究所 小傻瓜都能懂的 AstrBot QQ 机器人集成 MCP 功能实战指南 | szhshp 的第三边境研究所 《智人之上: 从石器时代到 AI 时代的信息网络简史》阅读笔记 | szhshp 的第三边境研究所 iPadOS 26 无法设置空间场景图片壁纸的解决方法 | szhshp 的第三边境研究所 《一路云海》(终) | szhshp 的第三边境研究所 《一路云海》(四): 如何不按套路旅行 | szhshp 的第三边境研究所 《一路云海》(三): In Ya Mellow Tone | szhshp 的第三边境研究所 《一路云海》(二): 关西世博参观纪实 | szhshp 的第三边境研究所 《一路云海》(一): 新的征程 | szhshp 的第三边境研究所 2025 大阪世博会 [ 3 天前-先到先得 ] 阶段 场馆预约必中独家攻略 | szhshp 的第三边境研究所 Hackathon 随想 | szhshp 的第三边境研究所 一杯双皮奶 | szhshp 的第三边境研究所 Armbian + CasaOS + NAS 配置指南 | szhshp 的第三边境研究所 Docker 构建镜像报错: error getting credentials - err: exit status 1, out: `` | szhshp 的第三边境研究所 Disqus RIP! 论过高的维护成本如何治疗固执的坏习惯 | szhshp 的第三边境研究所 炸弹猫桌游变体规则 | szhshp 的第三边境研究所 《小岛经济学》阅读笔记 | szhshp 的第三边境研究所 《金钱心理学》阅读笔记 | szhshp 的第三边境研究所 为知笔记 RIP: 迁移剩余的笔记 | szhshp 的第三边境研究所 2025 博客第十年展望 - 再见我的过去 | szhshp 的第三边境研究所 我在独立游戏里面致敬的作品 | szhshp 的第三边境研究所 《How to make thing faster》阅读笔记 | szhshp 的第三边境研究所 《The Art of Clean Code》阅读笔记 | szhshp 的第三边境研究所 《Clean Architecture: A Craftsman Guide to Software Structure and Design》阅读笔记 | szhshp 的第三边境研究所 《How AI Works》阅读笔记 | szhshp 的第三边境研究所 游戏策划废案 - Project Uranus | szhshp 的第三边境研究所 游戏策划废案 - Project X | szhshp 的第三边境研究所 人生第一款独立游戏开发复盘 | szhshp 的第三边境研究所 Trap of Life | szhshp 的第三边境研究所 如果我用手搓了个暗物质雏形 | szhshp 的第三边境研究所
Windows 下 Sublime Text 3 + EsLinter 的使用 | szhshp 的第...
2018-03-09 · via szhshp 的第三边境研究所

Meta

目录

配置啥的真的挺烦的, 写篇文章供大家参考

ESLint

很有名的一款JS代码规范检查用的插件

安装

首先需要npm, 这个没有外部·executable program·的结合是无法使用的


安装eslint, 这里全局安装, 因为后期Sublime会用绝对Path, 可以省去一些不必要的麻烦:

npm install -g eslint

安装完成后测试一下:

eslint -v

Linter的使用必须要配置文件, 我们可以在根目录创建一个新的配置文件, 跟着指导一步一步操作即可

eslint --init

然后可以对某JS文件进行测试, 看到正确输出的错误信息, 基本上就可以了。

eslint posts.js

G:\Dev\GitRepos\Coding\szhshp-subsites\source\src\templates\posts.js
   1:8   error  'React' is defined but never used              no-unused-vars
   4:1   error  Expected indentation of 4 spaces but found 2   indent
   4:35  error  Missing semicolon                              semi
   6:1   error  Expected indentation of 4 spaces but found 2   indent
   7:1   error  Expected indentation of 8 spaces but found 4   indent
   8:1   error  Expected indentation of 12 spaces but found 6  indent
   9:1   error  Expected indentation of 16 spaces but found 8  indent
  10:1   error  Expected indentation of 12 spaces but found 6  indent
  11:1   error  Expected indentation of 12 spaces but found 6  indent
  12:1   error  Expected indentation of 16 spaces but found 8  indent
  13:1   error  Expected indentation of 12 spaces but found 6  indent
  14:1   error  Expected indentation of 8 spaces but found 4   indent
  15:1   error  Expected indentation of 4 spaces but found 2   indent
  15:4   error  Missing semicolon                              semi
  16:2   error  Missing semicolon                              semi
  18:22  error  'graphql' is not defined                       no-undef
  27:2   error  Missing semicolon                              semi

✖ 17 problems (17 errors, 0 warnings)
  15 errors, 0 warnings potentially fixable with the `--fix` option.

SublimeLinter

比较烦的是Sublime Text 方面的配置

这里用的是ST 3.0版本

首先下载两个Package:

  • SublimeLinter
  • SublimeLinter-eslint

Sublime 端配置

// SublimeLinter Settings - User
{
    "debug": false,
    "paths": {
        "linux": [],
        "osx": [],
        "windows": "D:\\Tools_For_Work\\NodeJS\\node_global\\node_modules\\eslint"
    },
    "syntax_map": {
        "html (django)": "html",
        "html (rails)": "html",
        "html 5": "html",
        "javascript (babel)": "javascript",
        "magicpython": "python",
        "php": "html",
        "python django": "python",
        "pythonimproved": "python"
    }
}

最重要的是paths这个参数, 需要设置到全局的eslint的module的路径, 而且注意斜杠要进行转义

另外有一些格式可以进行配置, 即使用syntax_map参数进行配置, 这个非必须用默认的, 已经有很多功能了

03月12日 更新: 关于Airbnb的Linter规则的使用

默认的配置会检查linebreak, 有一些项目可能达到平台开发, 检查不同平台上的普通换行符, 就没有太大意义。当然如果不使用默认配置的话, 就可以用一些主流配置, 比如Airbnb的配置:

首先先完成上面所有工作后, 将配置文件改成这个样子:

{
    "extends": "airbnb"
}

然后全局安装几个缺少的包:

  1. eslint-config-airbnb
  2. eslint-plugin-jsx-a11y

配置文件放到项目根目录就可以, 另外不同的项目要不同的配置文件

03月22日 更新: 关于如何重载预设规则

如果你有一个规则不想使用,比如Airbnb里面必须要求函数有名字, 不允许使用匿名函数

首先你会看到报错信息得知这个规则的名称叫做func-names)

然后谷歌搜索一下就可以得知这个规则的设置

在然后在我们的规则文件里面添加对这个规则的自定义, 比如下面rules里面我将这个规则给关闭了

{
    "parserOptions": {
        "ecmaVersion": 8
    },
  "env": {
        "es6": true
    },
    "extends": "eslint:recommended",
    "globals": {
    },
    "plugins": [
    ],
    "rules": {
        "func-names": "off"
    }
}