isort 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eddd4ac245d4454fae469ae1562f8236c9d273e3d0fbf2197503928267957816
4
- data.tar.gz: cc278de73effc6a9e8c69d21b6cb5d2fa06a85542e084d9f93affdedb5bfc169
3
+ metadata.gz: a046b9382cc4f3416cfd1105cfb5c248c04a634cb0f9a3a95cb9c4ddab8938e2
4
+ data.tar.gz: 0ff466bd33cff96343da32c8483e9f5fc64cc437c3fd02674951434b25762027
5
5
  SHA512:
6
- metadata.gz: 32a5b91883075031985e3145fee1a321b40e90c8e031288492f53b3faaed65db183b1d3ce1ef6caf8754e3360eeefa94dcfecc2229a4a4d9e96e9f19aec62e02
7
- data.tar.gz: 731ea5737a2e677a87b056441349d8fbadc406cefa577e5eeffd424d3a3f522dfb19eea2ca518edf6bedd1bb840d80e51fe4a64099b4e3df5db513ed4ff241ec
6
+ metadata.gz: 0e3e720fca7b0947fc2f7c164898651863a0b816e5ec9316f51ada1e06fc86ef72066cad22a2a0ae0f531667afe54445dab638da9e226f2baeb81c18de851d7c
7
+ data.tar.gz: ebac9c17a54d5f0e499daece31cad74375f5969443326c1d47769a2b7b9fa081e1df27386b516baf71301606a28cc0174abe5426d296f7dca76a5cb87c41438c
data/CHANGELOG.md CHANGED
@@ -10,3 +10,11 @@
10
10
  - Support for require, require_relative, include, and extend statements
11
11
  - CLI interface
12
12
  - Preservation of code structure and spacing
13
+
14
+ ## [0.1.4] - 2024-12-29
15
+
16
+ - Second release
17
+
18
+ ### Added
19
+ - Import sorting functionality support for a whole directory
20
+ -
data/lib/isort/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Isort
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/isort.rb CHANGED
@@ -6,6 +6,7 @@ require 'optparse'
6
6
 
7
7
  module Isort
8
8
  class Error < StandardError; end
9
+
9
10
  class FileSorter
10
11
  def initialize(file_path)
11
12
  @file_path = file_path
@@ -13,7 +14,7 @@ module Isort
13
14
 
14
15
  def sort_imports
15
16
  # Read the file content
16
- lines = File.readlines(@file_path)
17
+ lines = File.readlines(@file_path, chomp: true).map { |line| line.gsub("\r", "") }
17
18
 
18
19
  # Separate import-related lines and other content
19
20
  imports = lines.select { |line| line =~ /^\s*(require|require_relative|include)\s/ }
@@ -70,7 +71,9 @@ module Isort
70
71
  # Remove duplicates and sort
71
72
  lines.uniq.sort
72
73
  end
74
+
73
75
  end
76
+
74
77
  class CLI
75
78
  def self.start
76
79
  options = {}
@@ -80,12 +83,23 @@ module Isort
80
83
  opts.on("-fFILE", "--file=FILE", "File to sort") do |file|
81
84
  options[:file] = file
82
85
  end
86
+ opts.on("-dDIRECTORY", "--directory=DIRECTORY", "Specify a directory to sort") do |dir|
87
+ options[:directory] = dir
88
+ end
83
89
  end.parse!
84
90
 
85
91
  if options[:file]
86
92
  sorter = FileSorter.new(options[:file])
87
93
  sorter.sort_and_format_imports
88
94
  puts "Imports sorted in #{options[:file]}"
95
+ elsif options[:directory]
96
+ count = 0
97
+ Dir.glob("#{options[:directory]}/**/*.rb").each do |file|
98
+ count += 1
99
+ sorter = FileSorter.new(file)
100
+ sorter.sort_and_format_imports
101
+ end
102
+ puts "Sorted imports in #{count} files in directory: #{options[:directory]}"
89
103
  else
90
104
  puts "Please specify a file using -f or --file"
91
105
  end
@@ -0,0 +1,11 @@
1
+ module Isort
2
+ class FileSorter
3
+ @file_path: untyped
4
+
5
+ def sort_and_format_imports: -> untyped
6
+
7
+ def sort_directory: -> untyped
8
+
9
+ def sort_imports: -> untyped
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - abhinvv1
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-28 00:00:00.000000000 Z
11
+ date: 2024-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optparse
@@ -87,6 +87,7 @@ files:
87
87
  - lib/isort/version.rb
88
88
  - sample.rb
89
89
  - sig/isort.rbs
90
+ - sig/isort/file_sorter.rbs
90
91
  homepage: https://github.com/abhinvv1/sort
91
92
  licenses:
92
93
  - MIT