nitrocop 0.0.1.pre → 0.0.1.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/nitrocop +20 -0
  3. data/lib/gem_builder.rb +114 -0
  4. data/lib/nitrocop.rb +12 -0
  5. metadata +13 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5796d300022f70d7dea66088e68ea908d09e16583068b096a285c4893473493a
4
- data.tar.gz: dae5536d6035f67546136f12ffe1fc52d602bdffc8dd5eeba120fec2313c4cd7
3
+ metadata.gz: a3018f9d77d349f662a66126ff4072ca7a7e4f32d61d01d30fdcce5a53db0229
4
+ data.tar.gz: a4d09fd544895a6b62fa00291818da56e80e38c69b012067c95a6df66e0427ef
5
5
  SHA512:
6
- metadata.gz: 118c1dfcadb2b1cfef9887b034da1bbbb99e496afa9f70075edeed9baef522a9ccc9f30543bd5d89706c9eeceda9950109f96fe91b518a0d637bd7e8521ac942
7
- data.tar.gz: 8cf8d948c812075b068479e25737a0d43999831f2dea87a018d6d62fe8c1049d96bb27076f88173ed91d4bd4ae1939669d768402ee9e8ce8e5c215c14014d909
6
+ metadata.gz: 3d86c279c4d6712b655a2efb11ec2c7ce847e7a8f5f9853ef63675d4bcd195d581aea0b75e2ca5948fb93946ba5d2e88ed4b94c0d2b9bc0dd5dbe001264466ac
7
+ data.tar.gz: 1f65c670dab59250d1d64e99d1674b77e00a029b9648eb9956cd210a2e4ac9d3bd9c90dbb6fcf18376fdd2e3614858bfca69e0cb2489cf7aa071bc9f3fc5ccc5
data/exe/nitrocop ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "nitrocop"
5
+
6
+ exe = Nitrocop.executable
7
+
8
+ if exe
9
+ exec(exe, *ARGV)
10
+ else
11
+ platform = defined?(Gem::Platform) ? Gem::Platform.local.to_s : RUBY_PLATFORM
12
+ abort <<~MSG
13
+ nitrocop: no precompiled binary for #{platform}
14
+
15
+ Supported platforms: arm64-darwin, x86_64-darwin, x86_64-linux, x86_64-linux-musl, aarch64-linux
16
+
17
+ To install from source (requires Rust 1.85+):
18
+ cargo install nitrocop
19
+ MSG
20
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "tmpdir"
5
+
6
+ # Builds nitrocop gems — both base (fallback) and platform-specific variants.
7
+ #
8
+ # Base gem: no binary, users on unsupported platforms get a helpful error.
9
+ # Platform gem: includes precompiled binary in libexec/.
10
+ class GemBuilder
11
+ GEM_SOURCE = File.expand_path("..", __dir__)
12
+
13
+ attr_reader :version, :platform, :binary_path
14
+
15
+ # @param version [String] gem version (e.g. "0.1.0")
16
+ # @param platform [String, nil] platform string (e.g. "arm64-darwin"), nil for base gem
17
+ # @param binary_path [String, nil] path to compiled binary, required for platform gems
18
+ def initialize(version:, platform: nil, binary_path: nil)
19
+ @version = version
20
+ @platform = platform
21
+ @binary_path = binary_path
22
+ end
23
+
24
+ def platform?
25
+ !platform.nil?
26
+ end
27
+
28
+ # Assembles gem contents into the given directory. Useful for testing.
29
+ # Returns the directory path.
30
+ def assemble(dir)
31
+ FileUtils.cp_r(File.join(GEM_SOURCE, "lib"), dir)
32
+ FileUtils.cp_r(File.join(GEM_SOURCE, "exe"), dir)
33
+
34
+ if platform?
35
+ raise "Binary not found: #{binary_path}" unless File.file?(binary_path)
36
+
37
+ libexec = File.join(dir, "libexec")
38
+ FileUtils.mkdir_p(libexec)
39
+ FileUtils.cp(binary_path, File.join(libexec, "nitrocop"))
40
+ FileUtils.chmod(0o755, File.join(libexec, "nitrocop"))
41
+ end
42
+
43
+ patch_version(dir)
44
+ write_gemspec(dir)
45
+ dir
46
+ end
47
+
48
+ # Builds the .gem file and moves it to output_dir.
49
+ # Returns the path to the built .gem file.
50
+ def build(output_dir: Dir.pwd)
51
+ Dir.mktmpdir("nitrocop-gem-") do |tmpdir|
52
+ assemble(tmpdir)
53
+
54
+ Dir.chdir(tmpdir) do
55
+ system("gem", "build", "nitrocop.gemspec", exception: true)
56
+ end
57
+
58
+ gem_file = Dir.glob(File.join(tmpdir, "nitrocop-*.gem")).first
59
+ dest = File.join(output_dir, File.basename(gem_file))
60
+ FileUtils.mv(gem_file, dest)
61
+ dest
62
+ end
63
+ end
64
+
65
+ # Returns the gemspec content as a string.
66
+ def gemspec_content
67
+ lines = []
68
+ lines << '# frozen_string_literal: true'
69
+ lines << ''
70
+ lines << 'require_relative "lib/nitrocop"'
71
+ lines << ''
72
+ lines << 'Gem::Specification.new do |spec|'
73
+ lines << ' spec.name = "nitrocop"'
74
+ lines << ' spec.version = Nitrocop::VERSION'
75
+ lines << " spec.platform = \"#{platform}\"" if platform?
76
+ lines << ' spec.authors = ["6"]'
77
+ lines << ''
78
+ lines << ' spec.summary = "Fast Ruby linter targeting RuboCop compatibility"'
79
+ if platform?
80
+ lines << ' spec.description = "A Ruby linter written in Rust that reads your existing .rubocop.yml " \\'
81
+ lines << ' "and runs 900+ cops. " \\'
82
+ lines << " \"Platform variant: #{platform}.\""
83
+ else
84
+ lines << ' spec.description = "A Ruby linter written in Rust that reads your existing .rubocop.yml " \\'
85
+ lines << ' "and runs 900+ cops."'
86
+ end
87
+ lines << ' spec.homepage = "https://github.com/6/nitrocop"'
88
+ lines << ' spec.license = "MIT"'
89
+ lines << ''
90
+ lines << ' spec.required_ruby_version = ">= 3.1.0"'
91
+ lines << ''
92
+ lines << ' spec.metadata["source_code_uri"] = spec.homepage'
93
+ lines << ' spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"'
94
+ lines << ''
95
+ lines << ' spec.files = Dir["lib/**/*", "exe/**/*", "libexec/**/*"]'
96
+ lines << ' spec.bindir = "exe"'
97
+ lines << ' spec.executables = ["nitrocop"]'
98
+ lines << 'end'
99
+ lines.join("\n") + "\n"
100
+ end
101
+
102
+ private
103
+
104
+ def patch_version(dir)
105
+ version_file = File.join(dir, "lib", "nitrocop.rb")
106
+ content = File.read(version_file)
107
+ content.sub!(/VERSION = ".*"/, %(VERSION = "#{version}"))
108
+ File.write(version_file, content)
109
+ end
110
+
111
+ def write_gemspec(dir)
112
+ File.write(File.join(dir, "nitrocop.gemspec"), gemspec_content)
113
+ end
114
+ end
data/lib/nitrocop.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nitrocop
4
+ VERSION = "0.0.1.pre3"
5
+
6
+ # Returns the path to the precompiled nitrocop binary, or nil if
7
+ # no binary is bundled (e.g. the base/fallback gem on an unsupported platform).
8
+ def self.executable
9
+ bin = File.expand_path("../libexec/nitrocop", __dir__)
10
+ bin if File.file?(bin) && File.executable?(bin)
11
+ end
12
+ end
metadata CHANGED
@@ -1,23 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nitrocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - '6'
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: Placeholder real release coming soon.
13
- executables: []
12
+ description: A Ruby linter written in Rust that reads your existing .rubocop.yml and
13
+ runs 900+ cops.
14
+ executables:
15
+ - nitrocop
14
16
  extensions: []
15
17
  extra_rdoc_files: []
16
- files: []
18
+ files:
19
+ - exe/nitrocop
20
+ - lib/gem_builder.rb
21
+ - lib/nitrocop.rb
17
22
  homepage: https://github.com/6/nitrocop
18
23
  licenses:
19
24
  - MIT
20
- metadata: {}
25
+ metadata:
26
+ source_code_uri: https://github.com/6/nitrocop
27
+ changelog_uri: https://github.com/6/nitrocop/releases
21
28
  rdoc_options: []
22
29
  require_paths:
23
30
  - lib