Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed May 31, 2022
1 parent 897e8ed commit 41eee72
Show file tree
Hide file tree
Showing 32 changed files with 465 additions and 474 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org/'
source "https://rubygems.org/"

gemspec

group :benchmark do
gem 'benchmark-ips'
gem 'kramdown'
gem 'redcarpet'
gem "benchmark-ips"
gem "kramdown"
gem "redcarpet"
end
111 changes: 56 additions & 55 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
# frozen_string_literal: true

require 'date'
require 'rake/clean'
require 'rake/extensiontask'
require 'digest/md5'
require "date"
require "rake/clean"
require "rake/extensiontask"
require "digest/md5"

host_os = RbConfig::CONFIG['host_os']
require 'devkit' if host_os == 'mingw32'
host_os = RbConfig::CONFIG["host_os"]
require "devkit" if host_os == "mingw32"

task default: [:test]

# Gem Spec
gem_spec = Gem::Specification.load('commonmarker.gemspec')
gem_spec = Gem::Specification.load("commonmarker.gemspec")

# Ruby Extension
Rake::ExtensionTask.new('commonmarker', gem_spec) do |ext|
ext.lib_dir = File.join('lib', 'commonmarker')
Rake::ExtensionTask.new("commonmarker", gem_spec) do |ext|
ext.lib_dir = File.join("lib", "commonmarker")
end

# Packaging
require 'bundler/gem_tasks'
require "bundler/gem_tasks"

# Testing
require 'rake/testtask'
require "rake/testtask"

Rake::TestTask.new('test:unit') do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/test_*.rb'
Rake::TestTask.new("test:unit") do |t|
t.libs << "lib"
t.libs << "test"
t.pattern = "test/test_*.rb"
t.verbose = true
t.warning = false
end

task 'test:unit' => :compile
desc "Run unit tests"
task "test:unit" => :compile

desc 'Run unit and conformance tests'
task test: %w[test:unit]
desc "Run unit and conformance tests"
task test: ["test:unit"]

require 'rubocop/rake_task'
require "rubocop/rake_task"

RuboCop::RakeTask.new(:rubocop)

desc 'Run benchmarks'
desc "Run benchmarks"
task :benchmark do
if ENV['FETCH_PROGIT']
`rm -rf test/progit`
`git clone https://github.com/progit/progit.git test/progit`
langs = %w[ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw]
if ENV["FETCH_PROGIT"]
%x(rm -rf test/progit)
%x(git clone https://github.com/progit/progit.git test/progit)
langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"]
langs.each do |lang|
`cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md`
%x(cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md)
end
end
$LOAD_PATH.unshift 'lib'
load 'test/benchmark.rb'
$LOAD_PATH.unshift("lib")
load "test/benchmark.rb"
end

desc 'Match C style of cmark'
desc "Match C style of cmark"
task :format do
sh 'clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h'
sh "clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h"
end

# Documentation
require 'rdoc/task'
require "rdoc/task"

desc 'Generate API documentation'
desc "Generate API documentation"
RDoc::Task.new do |rd|
rd.rdoc_dir = 'docs'
rd.main = 'README.md'
rd.rdoc_files.include 'README.md', 'lib/**/*.rb', 'ext/commonmarker/commonmarker.c'

rd.options << '--markup tomdoc'
rd.options << '--inline-source'
rd.options << '--line-numbers'
rd.options << '--all'
rd.options << '--fileboxes'
rd.rdoc_dir = "docs"
rd.main = "README.md"
rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/commonmarker/commonmarker.c")

rd.options << "--markup tomdoc"
rd.options << "--inline-source"
rd.options << "--line-numbers"
rd.options << "--all"
rd.options << "--fileboxes"
end

desc 'Generate the documentation and run a web server'
desc "Generate the documentation and run a web server"
task serve: [:rdoc] do
require 'webrick'
require "webrick"

puts 'Navigate to http://localhost:3000 to see the docs'
puts "Navigate to http://localhost:3000 to see the docs"

server = WEBrick::HTTPServer.new Port: 3000
server.mount '/', WEBrick::HTTPServlet::FileHandler, 'docs'
trap('INT') { server.stop }
server = WEBrick::HTTPServer.new(Port: 3000)
server.mount("/", WEBrick::HTTPServlet::FileHandler, "docs")
trap("INT") { server.stop }
server.start
end

desc 'Generate and publish docs to gh-pages'
desc "Generate and publish docs to gh-pages"
task publish: [:rdoc] do
require 'tmpdir'
require 'shellwords'
require "tmpdir"
require "shellwords"

Dir.mktmpdir do |tmp|
system "mv docs/* #{tmp}"
system 'git checkout origin/gh-pages'
system 'rm -rf *'
system "git checkout origin/gh-pages"
system "rm -rf *"
system "mv #{tmp}/* ."
message = Shellwords.escape("Site updated at #{Time.now.utc}")
system 'git add .'
system "git add ."
system "git commit -am #{message}"
system 'git push origin gh-pages --force'
system 'git checkout master'
system 'echo yolo'
system "git push origin gh-pages --force"
system "git checkout master"
system "echo yolo"
end
end
53 changes: 26 additions & 27 deletions commonmarker.gemspec
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'commonmarker/version'
require "commonmarker/version"

Gem::Specification.new do |s|
s.name = 'commonmarker'
s.name = "commonmarker"
s.version = CommonMarker::VERSION
s.summary = 'CommonMark parser and renderer. Written in C, wrapped in Ruby.'
s.description = 'A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library.'
s.authors = ['Garen Torikian', 'Ashe Connor']
s.homepage = 'https://github.com/gjtorikian/commonmarker'
s.license = 'MIT'
s.summary = "CommonMark parser and renderer. Written in C, wrapped in Ruby."
s.description = "A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library."
s.authors = ["Garen Torikian", "Ashe Connor"]
s.homepage = "https://github.com/gjtorikian/commonmarker"
s.license = "MIT"

s.files = %w[LICENSE.txt README.md Rakefile commonmarker.gemspec bin/commonmarker]
s.files += Dir.glob('lib/**/*.rb')
s.files += Dir.glob('ext/commonmarker/*.*')
s.test_files = Dir.glob('test/**/*').reject { |f| f == 'test/benchinput.md' || f.start_with?('test/progit/') }
s.extensions = ['ext/commonmarker/extconf.rb']
s.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"]
s.files += Dir.glob("lib/**/*.rb")
s.files += Dir.glob("ext/commonmarker/*.*")
s.extensions = ["ext/commonmarker/extconf.rb"]

s.executables = ['commonmarker']
s.require_paths = %w[lib ext]
s.required_ruby_version = ['>= 2.6', '< 4.0']
s.executables = ["commonmarker"]
s.require_paths = ["lib", "ext"]
s.required_ruby_version = [">= 2.6", "< 4.0"]

s.metadata['rubygems_mfa_required'] = 'true'
s.metadata["rubygems_mfa_required"] = "true"

s.rdoc_options += ['-x', 'ext/commonmarker/cmark/.*']
s.rdoc_options += ["-x", "ext/commonmarker/cmark/.*"]

s.add_development_dependency 'awesome_print'
s.add_development_dependency 'json', '~> 2.3'
s.add_development_dependency 'minitest', '~> 5.6'
s.add_development_dependency 'minitest-focus', '~> 1.1'
s.add_development_dependency 'rake'
s.add_development_dependency 'rake-compiler', '~> 0.9'
s.add_development_dependency 'rdoc', '~> 6.2'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'rubocop-standard'
s.add_development_dependency("awesome_print")
s.add_development_dependency("json", "~> 2.3")
s.add_development_dependency("minitest", "~> 5.6")
s.add_development_dependency("minitest-focus", "~> 1.1")
s.add_development_dependency("rake")
s.add_development_dependency("rake-compiler", "~> 0.9")
s.add_development_dependency("rdoc", "~> 6.2")
s.add_development_dependency("rubocop")
s.add_development_dependency("rubocop-standard")
end
18 changes: 9 additions & 9 deletions lib/commonmarker.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'commonmarker/commonmarker'
require 'commonmarker/config'
require 'commonmarker/node'
require 'commonmarker/renderer'
require 'commonmarker/renderer/html_renderer'
require 'commonmarker/version'
require "commonmarker/commonmarker"
require "commonmarker/config"
require "commonmarker/node"
require "commonmarker/renderer"
require "commonmarker/renderer/html_renderer"
require "commonmarker/version"

begin
require 'awesome_print'
require "awesome_print"
rescue LoadError; end # rubocop:disable Lint/SuppressedException
module CommonMarker
# Public: Parses a Markdown string into an HTML string.
Expand All @@ -23,7 +23,7 @@ def self.render_html(text, options = :DEFAULT, extensions = [])
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)

opts = Config.process_options(options, :render)
Node.markdown_to_html(text.encode('UTF-8'), opts, extensions)
Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
end

# Public: Parses a Markdown string into a `document` node.
Expand All @@ -37,7 +37,7 @@ def self.render_doc(text, options = :DEFAULT, extensions = [])
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)

opts = Config.process_options(options, :parse)
text = text.encode('UTF-8')
text = text.encode("UTF-8")
Node.parse_document(text, text.bytesize, opts, extensions)
end
end
6 changes: 3 additions & 3 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Config
SMART: (1 << 10),
LIBERAL_HTML_TAG: (1 << 12),
FOOTNOTES: (1 << 13),
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14)
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
}.freeze,
render: {
DEFAULT: 0,
Expand All @@ -28,9 +28,9 @@ module Config
FOOTNOTES: (1 << 13),
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15),
FULL_INFO_STRING: (1 << 16)
FULL_INFO_STRING: (1 << 16),
}.freeze,
format: %i[html xml commonmark plaintext].freeze
format: [:html, :xml, :commonmark, :plaintext].freeze,
}.freeze

def self.process_options(option, type)
Expand Down
12 changes: 6 additions & 6 deletions lib/commonmarker/node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'commonmarker/node/inspect'
require "commonmarker/node/inspect"

module CommonMarker
class Node
Expand All @@ -27,7 +27,7 @@ def walk(&block)
# Returns a {String}.
def to_html(options = :DEFAULT, extensions = [])
opts = Config.process_options(options, :render)
_render_html(opts, extensions).force_encoding('utf-8')
_render_html(opts, extensions).force_encoding("utf-8")
end

# Public: Convert the node to an XML string.
Expand All @@ -37,7 +37,7 @@ def to_html(options = :DEFAULT, extensions = [])
# Returns a {String}.
def to_xml(options = :DEFAULT)
opts = Config.process_options(options, :render)
_render_xml(opts).force_encoding('utf-8')
_render_xml(opts).force_encoding("utf-8")
end

# Public: Convert the node to a CommonMark string.
Expand All @@ -48,7 +48,7 @@ def to_xml(options = :DEFAULT)
# Returns a {String}.
def to_commonmark(options = :DEFAULT, width = 120)
opts = Config.process_options(options, :render)
_render_commonmark(opts, width).force_encoding('utf-8')
_render_commonmark(opts, width).force_encoding("utf-8")
end

# Public: Convert the node to a plain text string.
Expand All @@ -59,7 +59,7 @@ def to_commonmark(options = :DEFAULT, width = 120)
# Returns a {String}.
def to_plaintext(options = :DEFAULT, width = 120)
opts = Config.process_options(options, :render)
_render_plaintext(opts, width).force_encoding('utf-8')
_render_plaintext(opts, width).force_encoding("utf-8")
end

# Public: Iterate over the children (if any) of the current pointer.
Expand All @@ -76,7 +76,7 @@ def each

# Deprecated: Please use `each` instead
def each_child(&block)
warn '[DEPRECATION] `each_child` is deprecated. Please use `each` instead.'
warn("[DEPRECATION] `each_child` is deprecated. Please use `each` instead.")
each(&block)
end
end
Expand Down
Loading

0 comments on commit 41eee72

Please sign in to comment.