Module: Vivlio::Starter::CLI::LintCommands

Defined in:
lib/vivlio/starter/cli/lint.rb

Overview

textlint による文章校正コマンド

Defined Under Namespace

Classes: LintError, LintRunner

Constant Summary collapse

DEFAULT_CONFIG_FALLBACK =
File.join(Common::CONFIG_DIR, '.textlintrc.yml')
TEXTLINT_ALLOWLIST_RELATIVE =

textlint 用サポート YAML(allowlist/prh)の既定パス

File.join(Common::CONFIG_DIR, 'textlint_allowlist.yml')
TEXTLINT_PRH_RELATIVE =
File.join(Common::CONFIG_DIR, 'textlint_prh.yml')
LINT_DESC =
{
  short: 'contents/ 以下の Markdown を textlint で検査します',
  long: <<~DESC
    contents/ ディレクトリ以下の Markdown ファイルを textlint で検査します。
    引数を指定しない場合は全ての Markdown が対象です。章のベース名(11-install など)を
    指定すると、そのファイルのみを検査します(拡張子や contents/ の省略可)。

    章番号のみ、または範囲指定も可能です:
      章番号のみ: vs lint 91 93      # 91-*.md と 93-*.md を検査
      範囲指定:   vs lint 11-21      # 11-*.md から 21-*.md を検査

    例:
      vs lint                 # 全 Markdown を検査
      vs lint 11-install      # 11-install.md のみ検査
      vs lint 11-install 21-customize
      vs lint 91 93           # 91-*.md と 93-*.md を検査
      vs lint 11-21           # 11-*.md から 21-*.md の範囲を検査
      vs lint:check           # lint のエイリアス

    オプション:
      --config PATH    使用する .textlintrc.yml のパスを切り替えます。
                       省略時は book.yml の lint.config が使われます。
      --format NAME    textlint の出力フォーマットを指定します。
                       省略時は book.yml の lint.format(既定: stylish)が使われます。
      --fix            自動修正可能なエラーを修正します。
  DESC
}.freeze
DEFAULT_FORMAT_FALLBACK =
'stylish'
TEXTLINT_ENV_VAR =
'VIVLIO_TEXTLINT_BIN'
TextLintCommands =

後方互換: 旧 TextLintCommands 定数を維持

LintCommands

Class Method Summary collapse

Class Method Details

.default_lint_configObject

CONFIG.lint セクションから設定ファイルパスを取得(シンボルキー前提)



81
82
83
84
85
86
87
# File 'lib/vivlio/starter/cli/lint.rb', line 81

def self.default_lint_config
  value = Common::CONFIG.lint&.config
  value = nil if Common.blank?(value)
  value || DEFAULT_CONFIG_FALLBACK
rescue StandardError
  DEFAULT_CONFIG_FALLBACK
end

.default_lint_formatObject

CONFIG.lint セクションから出力フォーマットを取得(シンボルキー前提)



90
91
92
93
94
95
96
97
# File 'lib/vivlio/starter/cli/lint.rb', line 90

def self.default_lint_format
  value = Common::CONFIG.lint&.format
  value = nil if Common.blank?(value)
  format = value || DEFAULT_FORMAT_FALLBACK
  format.to_s.strip.empty? ? DEFAULT_FORMAT_FALLBACK : format
rescue StandardError
  DEFAULT_FORMAT_FALLBACK
end

.execute_lint(targets, options = {}) ⇒ Object



99
100
101
# File 'lib/vivlio/starter/cli/lint.rb', line 99

def self.execute_lint(targets, options = {})
  LintRunner.new(targets, options).call
end