【问题标题】:typescript linter for CodeMirrorCodeMirror 的打字稿短绒
【发布时间】:2023-03-25 04:59:01
【问题描述】:

我在我的一个 CMS 应用程序之一中使用 CodeMirror 编辑器。有人对将 typescript linter 合并到 CodeMirror 有任何建议/经验吗?

附:我知道 ts lint https://www.npmjs.com/package/tslint 但如何合并它并不明显。

【问题讨论】:

    标签: typescript codemirror


    【解决方案1】:

    这应该不是问题,您只需安装tsd

    $ npm install -g tsd
    

    在您的项目中安装 CodeMirror 类型定义:

    # from your project folder
    $ tsd install codemirror --save
    

    这将创建一个名为typings 的文件夹,其中将包含一个归档codemirror.d.ts

    然后您可以在调用 CodeMirror API 的 TypeScript 文件中添加对此文件的引用:

    /// <reference path="../typings/codemirror/codemirror.d.ts" />
    
    // USE CODE MIRROR HERE
    

    完成编码后,您可以使用Gulpgulp-tslint

    # npm install gulp gulp-tslint vinyl-source-stream vinyl-buffer --save-dev
    

    创建gulpfile.js

    var gulp        = require("gulp"),
        source      = require("vinyl-source-stream"),
        buffer      = require("vinyl-buffer"),
        tslint      = require("gulp-tslint");
    
    
    gulp.task("lint", function() {
      return gulp.src([
                    __dirname + "/source/**/**.ts", // Path to your TS files
                  ])
                 .pipe(tslint())
                 .pipe(tslint.report("verbose"));
    });
    

    最后运行 Gulp 任务:

    $ gulp lint
    

    如果您需要有关 Gulp 的更多帮助,请查看Official Getting Started

    【讨论】:

      【解决方案2】:

      您需要使用 lint 插件:http://codemirror.net/doc/manual.html#addon_lint 提供来自 tslint -&gt; code mirror 的 lint 错误

      更多

      你甚至可以将 lint 插件包装成更好的东西,比如基于 promise 的 linter(警告复杂代码,但只是一个有效的演示 ?)https://github.com/basarat/tsb/blob/master/src/app/codemirror/codeEditor.tsx / https://github.com/basarat/tsb/blob/master/src/app/codemirror/addons/linter.ts

      【讨论】:

      • 我第一次阅读这个问题时理解了错误的意思,但现在我看到了你的答案,我认为你的答案是正确的。
      猜你喜欢
      • 2016-09-02
      • 2022-08-09
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2018-01-22
      • 2021-07-27
      • 1970-01-01
      相关资源
      最近更新 更多