@4cm4k1/grunt-standard 中文文档教程

发布于 8年前 浏览 51 项目主页 更新于 3年前

grunt-standard JavaScript Standard Style

JavaScript 标准样式 的 Grunt 插件

基于 @pdehaan/grunt-standard

依赖是最新的!

Install

以下 shell 命令会将 grunt-standard 安装到项目的 package.json 中的 devDependencies

npm

npm install @4cm4k1/grunt-standard --save-dev

Yarn

yarn add @4cm4k1/grunt-standard --dev

Assumptions

  • You have the latest version of grunt in your project's package.json's devDependencies.
  • You have added the npm task to your project's Gruntfile.js.
  • You are running the latest version of node.
grunt.loadNpmTasks('grunt-standard')

Configure

在项目的 Gruntfile.js 中,将名为 standard 的部分添加到传递到 grunt.initConfig() 的数据对象中。

Default

在此示例中,默认选项用于检查根目录、lib/tasks/ 目录中指定的 *.js 文件:

grunt.initConfig({
  standard: {
    app: {
      src: [
        '{,lib/,tasks/}*.js'
      ]
    }
  }
})

Custom

options.format

  • Type: Boolean
  • Default: false
  • Action: Auto-format source files using standard-format.

options.lint

在此示例中,format 选项设置为 true,因此源文件将在被 lint 之前自动格式化(并写回磁盘):

grunt.initConfig({
  standard: {
    options: {
      format: true
    },
    app: {
      src: [
        '{,lib/,tasks/}*.js'
      ]
    }
  }
})

Contribute

grunt-standard JavaScript Standard Style

Grunt Plugin for JavaScript Standard Style Linting and Formatting

Based on @pdehaan/grunt-standard

Dependencies up-to-date!

Install

The following shell commands will install grunt-standard to your project's package.json in devDependencies.

npm

npm install @4cm4k1/grunt-standard --save-dev

Yarn

yarn add @4cm4k1/grunt-standard --dev

Assumptions

  • You have the latest version of grunt in your project's package.json's devDependencies.
  • You have added the npm task to your project's Gruntfile.js.
  • You are running the latest version of node.
grunt.loadNpmTasks('grunt-standard')

Configure

In your project's Gruntfile.js, add a section named standard to the data object passed into grunt.initConfig().

Default

In this example, the default options are used to lint the specified *.js files in the root, lib/, and tasks/ directories:

grunt.initConfig({
  standard: {
    app: {
      src: [
        '{,lib/,tasks/}*.js'
      ]
    }
  }
})

Custom

options.format

  • Type: Boolean
  • Default: false
  • Action: Auto-format source files using standard-format.

options.lint

In this example, the format option is set to true so the source files will be auto-formatted (and written back to disk) before being linted:

grunt.initConfig({
  standard: {
    options: {
      format: true
    },
    app: {
      src: [
        '{,lib/,tasks/}*.js'
      ]
    }
  }
})

Contribute

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文