gitmoji-regex 1.0.2 → 1.0.3

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.
data/REEK ADDED
File without changes
data/RUBOCOP.md ADDED
@@ -0,0 +1,71 @@
1
+ # RuboCop Usage Guide
2
+
3
+ ## Overview
4
+
5
+ A tale of two RuboCop plugin gems.
6
+
7
+ ### RuboCop Gradual
8
+
9
+ This project uses `rubocop_gradual` instead of vanilla RuboCop for code style checking. The `rubocop_gradual` tool allows for gradual adoption of RuboCop rules by tracking violations in a lock file.
10
+
11
+ ### RuboCop LTS
12
+
13
+ This project uses `rubocop-lts` to ensure, on a best-effort basis, compatibility with Ruby >= 1.9.2.
14
+ RuboCop rules are meticulously configured by the `rubocop-lts` family of gems to ensure that a project is compatible with a specific version of Ruby. See: https://rubocop-lts.gitlab.io for more.
15
+
16
+ ## Checking RuboCop Violations
17
+
18
+ To check for RuboCop violations in this project, always use:
19
+
20
+ ```bash
21
+ bundle exec rake rubocop_gradual:check
22
+ ```
23
+
24
+ **Do not use** the standard RuboCop commands like:
25
+ - `bundle exec rubocop`
26
+ - `rubocop`
27
+
28
+ ## Understanding the Lock File
29
+
30
+ The `.rubocop_gradual.lock` file tracks all current RuboCop violations in the project. This allows the team to:
31
+
32
+ 1. Prevent new violations while gradually fixing existing ones
33
+ 2. Track progress on code style improvements
34
+ 3. Ensure CI builds don't fail due to pre-existing violations
35
+
36
+ ## Common Commands
37
+
38
+ - **Check violations**
39
+ - `bundle exec rake rubocop_gradual`
40
+ - `bundle exec rake rubocop_gradual:check`
41
+ - **(Safe) Autocorrect violations, and update lockfile if no new violations**
42
+ - `bundle exec rake rubocop_gradual:autocorrect`
43
+ - **Force update the lock file (w/o autocorrect) to match violations present in code**
44
+ - `bundle exec rake rubocop_gradual:force_update`
45
+
46
+ ## Workflow
47
+
48
+ 1. Before submitting a PR, run `bundle exec rake rubocop_gradual:autocorrect`
49
+ a. or just the default `bundle exec rake`, as autocorrection is a pre-requisite of the default task.
50
+ 2. If there are new violations, either:
51
+ - Fix them in your code
52
+ - Run `bundle exec rake rubocop_gradual:force_update` to update the lock file (only for violations you can't fix immediately)
53
+ 3. Commit the updated `.rubocop_gradual.lock` file along with your changes
54
+
55
+ ## Never add inline RuboCop disables
56
+
57
+ Do not add inline `rubocop:disable` / `rubocop:enable` comments anywhere in the codebase (including specs, except when following the few existing `rubocop:disable` patterns for a rule already being disabled elsewhere in the code). We handle exceptions in two supported ways:
58
+
59
+ - Permanent/structural exceptions: prefer adjusting the RuboCop configuration (e.g., in `.rubocop.yml`) to exclude a rule for a path or file pattern when it makes sense project-wide.
60
+ - Temporary exceptions while improving code: record the current violations in `.rubocop_gradual.lock` via the gradual workflow:
61
+ - `bundle exec rake rubocop_gradual:autocorrect` (preferred; will autocorrect what it can and update the lock only if no new violations were introduced)
62
+ - If needed, `bundle exec rake rubocop_gradual:force_update` (as a last resort when you cannot fix the newly reported violations immediately)
63
+
64
+ In general, treat the rules as guidance to follow; fix violations rather than ignore them. For example, RSpec conventions in this project expect `described_class` to be used in specs that target a specific class under test.
65
+
66
+ ## Benefits of rubocop_gradual
67
+
68
+ - Allows incremental adoption of code style rules
69
+ - Prevents CI failures due to pre-existing violations
70
+ - Provides a clear record of code style debt
71
+ - Enables focused efforts on improving code quality over time
data/SECURITY.md CHANGED
@@ -7,8 +7,16 @@
7
7
  | 1.latest | ✅ |
8
8
  | 0.latest | ⛔️ |
9
9
 
10
- ## Reporting a Vulnerability
10
+ ## Security contact information
11
11
 
12
- Peter Boling is the primary maintainer of this gem. Please find a way
13
- to [contact him directly](https://railsbling.com/contact) to report the issue. Include as much relevant information as
14
- possible.
12
+ To report a security vulnerability, please use the
13
+ [Tidelift security contact](https://tidelift.com/security).
14
+ Tidelift will coordinate the fix and disclosure.
15
+
16
+ ## Additional Support
17
+
18
+ If you are interested in support for versions older than the latest release,
19
+ please consider sponsoring the project / maintainer @ https://liberapay.com/pboling/donate,
20
+ or find other sponsorship links in the [README].
21
+
22
+ [README]: README.md
@@ -0,0 +1 @@
1
+ 5fb52a48785f097e9f81632ccec8cf026be432bb1f32e057d3cf61d7ef725faf
@@ -0,0 +1 @@
1
+ 3b6e33a6cd5c90c16730ca1ae2b405629e23635b464b65cec25a7a9a6a6898fd536d84f0499c579c9517d3b98d7c9facc3d10e82208813b5debfac317456e653
@@ -0,0 +1 @@
1
+ a88394b8f30ae9cab79175d658d6dbcc1e1a5dfb819808a1292edc3f0f97d29b
@@ -0,0 +1 @@
1
+ e64c9581a9156845db3ab54445bb2e7fc0c51788b5b6db1d7fdc50520b9922c7a237e85ecb071251fdc5846beac2bbea432a6cb1a5e6ae522a5ae11a98d48d4b
@@ -6,47 +6,74 @@ require "json"
6
6
 
7
7
  # Download the list of all possible gitmojis from the project's github repository
8
8
  module Gitmoji
9
- # Regex provides the namespace for this gem
9
+ # Namespace for the regex and maintenance tools provided by this gem.
10
10
  module Regex
11
- # Reference provides utility tools for maintaining and testing this gem
11
+ # Reference provides utility tools for maintaining and testing this gem.
12
+ #
13
+ # It can compare the cached upstream gitmoji list with the latest
14
+ # fetched list, and can regenerate the library source from a template
15
+ # to include an up-to-date regular expression.
12
16
  class Reference
17
+ # Remote source of truth for the gitmoji JSON document.
13
18
  GITMOJI_REFERENCE = "https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json"
19
+ # Path to the cached JSON document bundled in this repository.
14
20
  GITMOJI_PATH = "src/gitmojis.json"
21
+ # Path to the library file that contains the REGEX constant.
15
22
  LIB_SRC = "lib/gitmoji/regex.rb"
23
+ # Path to the ERB-like template that is used to generate LIB_SRC.
16
24
  TEMPLATE_SRC = "src/regex.rb"
17
25
 
18
26
  include Singleton
19
27
 
28
+ # Compare the cached JSON-derived regex with the latest fetched regex.
29
+ #
30
+ # @return [Boolean] true if the regex generated from the cached JSON
31
+ # matches the regex generated from the freshly fetched JSON.
20
32
  def compare_json
21
33
  return true if cached_pattern == fetched_pattern
22
34
 
23
35
  false
24
36
  end
25
37
 
38
+ # Regex generated from the cached JSON file.
39
+ # @return [Regexp]
26
40
  def cached_pattern
27
41
  pattern(cached)
28
42
  end
29
43
 
44
+ # Regex generated from the fetched remote JSON.
45
+ # @return [Regexp]
30
46
  def fetched_pattern
31
47
  pattern(fetch)
32
48
  end
33
49
 
50
+ # Compare the current library source with the next generated source.
51
+ #
52
+ # @return [Boolean] true if no changes are needed (files are equal).
34
53
  def compare_src
35
54
  return true if current_src == next_src
36
55
 
37
56
  false
38
57
  end
39
58
 
59
+ # Read the current library source file that defines REGEX.
60
+ # @return [String]
40
61
  def current_src
41
62
  File.read(LIB_SRC)
42
63
  end
43
64
 
65
+ # Build the next library source content from the template and fetched data.
66
+ # @return [String] the prospective library source content.
44
67
  def next_src
45
68
  template_src = File.read(TEMPLATE_SRC)
46
- template_src = template_src.sub(/% gitmojiRegex %/, pattern(fetch).to_s)
69
+ template_src = template_src.sub("% gitmojiRegex %", pattern(fetch).to_s)
47
70
  template_src.to_s
48
71
  end
49
72
 
73
+ # Parse a JSON body and return the list of emoji strings.
74
+ #
75
+ # @param body [String, nil] the JSON document to parse; defaults to cached JSON
76
+ # @return [Array<String>] list of emoji characters
50
77
  def to_a(body = nil)
51
78
  body ||= cached
52
79
  json = JSON.parse(body)
@@ -54,6 +81,10 @@ module Gitmoji
54
81
  gitmoji.map { |g| g["emoji"] }
55
82
  end
56
83
 
84
+ # Write the freshly fetched JSON to the cache file.
85
+ #
86
+ # Also clears memoized cached values.
87
+ # @return [Integer] number of bytes written
57
88
  def write_json
58
89
  file = File.write(GITMOJI_PATH, fetch)
59
90
  @cached = nil
@@ -61,20 +92,29 @@ module Gitmoji
61
92
  file
62
93
  end
63
94
 
95
+ # Regenerate the library file from the template and fetched data.
96
+ # @return [Integer] number of bytes written
64
97
  def write_src
65
98
  File.write(LIB_SRC, next_src)
66
99
  end
67
100
 
68
101
  private
69
102
 
103
+ # Build the union regex from a JSON document body.
104
+ # @param body [String]
105
+ # @return [Regexp]
70
106
  def pattern(body)
71
107
  Regexp.union(to_a(body))
72
108
  end
73
109
 
110
+ # Fetch the latest gitmoji JSON from the remote source.
111
+ # @return [String] the raw response body as a string
74
112
  def fetch
75
113
  @fetch ||= HTTP.get(GITMOJI_REFERENCE).body
76
114
  end
77
115
 
116
+ # Read the cached gitmoji JSON from disk.
117
+ # @return [String]
78
118
  def cached
79
119
  @cached ||= File.read(GITMOJI_PATH)
80
120
  end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitmoji
4
+ # Namespace for all functionality provided by the gitmoji-regex gem.
4
5
  module Regex
6
+ # Version namespace housing the gem version constant.
5
7
  module Version
6
- VERSION = "1.0.2"
8
+ # The version of the gitmoji-regex gem.
9
+ # @return [String]
10
+ VERSION = "1.0.3"
7
11
  end
8
12
  end
9
13
  end
data/lib/gitmoji/regex.rb CHANGED
@@ -3,11 +3,26 @@
3
3
  require "version_gem"
4
4
 
5
5
  require "gitmoji/regex/version"
6
- require "gitmoji/regex/reference"
6
+ # Reference file isn't needed at runtime.
7
+ # require "gitmoji/regex/reference"
8
+ # Used to update the source of the gem (literally this file) when a new Gitmoji is added to the official list.
9
+ # See: bin/refresh
7
10
 
8
11
  module Gitmoji
12
+ # Namespace for all functionality provided by the gitmoji-regex gem.
9
13
  module Regex
10
- REGEX = Regexp.new("(?-mix:🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑‍💻|💸|🧵|🦺)")
14
+ # Regular expression that matches any official Gitmoji emoji.
15
+ #
16
+ # You can use this to validate commit messages or extract leading
17
+ # gitmoji from strings.
18
+ #
19
+ # Examples:
20
+ # # Validate a commit title starts with a gitmoji
21
+ # (Gitmoji::Regex::REGEX =~ "✨ Add feature") #=> 0
22
+ #
23
+ # # Extract all gitmojis from text
24
+ # "✨ Fix bug 🐛".scan(Gitmoji::Regex::REGEX) #=> ["✨", "🐛"]
25
+ REGEX = Regexp.new("(?-mix:🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑‍💻|💸|🧵|🦺|✈️)")
11
26
  end
12
27
  end
13
28
 
@@ -1,6 +1,31 @@
1
1
  module Gitmoji
2
2
  module Regex
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+ REGEX: Regexp
4
+
5
+ module Version
6
+ VERSION: String
7
+ end
8
+
9
+ class Reference
10
+ GITMOJI_REFERENCE: String
11
+ GITMOJI_PATH: String
12
+ LIB_SRC: String
13
+ TEMPLATE_SRC: String
14
+
15
+ def compare_json: () -> bool
16
+ def cached_pattern: () -> Regexp
17
+ def fetched_pattern: () -> Regexp
18
+ def compare_src: () -> bool
19
+ def current_src: () -> String
20
+ def next_src: () -> String
21
+ def to_a: (?String) -> Array[String]
22
+ def write_json: () -> Integer
23
+ def write_src: () -> Integer
24
+
25
+ private
26
+ def pattern: (String) -> Regexp
27
+ def fetch: () -> String
28
+ def cached: () -> String
29
+ end
5
30
  end
6
31
  end
data/src/gitmojis.json CHANGED
@@ -93,7 +93,7 @@
93
93
  "emoji": "🔒️",
94
94
  "entity": "&#x1f512;",
95
95
  "code": ":lock:",
96
- "description": "Fix security issues.",
96
+ "description": "Fix security or privacy issues.",
97
97
  "name": "lock",
98
98
  "semver": "patch"
99
99
  },
@@ -427,7 +427,7 @@
427
427
  },
428
428
  {
429
429
  "emoji": "⚗️",
430
- "entity": "&#128248;",
430
+ "entity": "&#x2697;",
431
431
  "code": ":alembic:",
432
432
  "description": "Perform experiments.",
433
433
  "name": "alembic",
@@ -478,7 +478,7 @@
478
478
  "entity": "&#x1f4ab;",
479
479
  "code": ":dizzy:",
480
480
  "description": "Add or update animations and transitions.",
481
- "name": "animation",
481
+ "name": "dizzy",
482
482
  "semver": "patch"
483
483
  },
484
484
  {
@@ -584,6 +584,14 @@
584
584
  "description": "Add or update code related to validation.",
585
585
  "name": "safety-vest",
586
586
  "semver": null
587
+ },
588
+ {
589
+ "emoji": "✈️",
590
+ "entity": "&#x2708;",
591
+ "code": ":airplane:",
592
+ "description": "Improve offline support.",
593
+ "name": "airplane",
594
+ "semver": null
587
595
  }
588
596
  ]
589
597
  }
data.tar.gz.sig CHANGED
Binary file