[feature/47] :: applied the camelcase naming convention#48
[feature/47] :: applied the camelcase naming convention#48wellfernandes merged 30 commits intodevelopfrom
Conversation
WalkthroughThis update introduces a centralized Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Mocker
participant EntityPkg as Entity Package (e.g., Address, Person)
User->>Mocker: NewMocker("ptbr")
Note right of Mocker: Sets language via translations package
User->>Mocker: Address()
Mocker->>EntityPkg: GenerateAddress()
EntityPkg-->>Mocker: *Address
Mocker-->>User: *Address
User->>Mocker: Phone()
Mocker->>EntityPkg: GeneratePhone()
EntityPkg-->>Mocker: *Phone
Mocker-->>User: *Phone
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used🧠 Learnings (2)📓 Common learningsinternal/cli/cli_constants.go (2)🧬 Code Graph Analysis (1)internal/cli/cli_constants.go (1)
🔇 Additional comments (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
README.md(1 hunks)cmd/mocai/cli_constants.go(2 hunks)docs/localization/pt/README-PT.md(1 hunks)examples/main.go(4 hunks)main.go(0 hunks)pkg/mocai/entities/company/countries/brazilian_company.go(1 hunks)pkg/mocai/entities/company/countries/errors.go(1 hunks)pkg/mocai/entities/company/countries/generator_test.go(2 hunks)pkg/mocai/entities/company/generator.go(0 hunks)pkg/mocai/entities/cpf/generator.go(1 hunks)pkg/mocai/entities/national_id/countries/brazilian_national_id.go(2 hunks)pkg/mocai/entities/person/errors.go(1 hunks)pkg/mocai/entities/person/generator.go(2 hunks)pkg/mocai/entities/phone/errors.go(1 hunks)pkg/mocai/entities/phone/generator.go(2 hunks)pkg/mocai/entities/vote_registration/countries/brazilian_vote_registration.go(1 hunks)
💤 Files with no reviewable changes (2)
- pkg/mocai/entities/company/generator.go
- main.go
🧰 Additional context used
🧠 Learnings (2)
pkg/mocai/entities/company/countries/brazilian_company.go (1)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
pkg/mocai/entities/company/countries/errors.go (1)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
🧬 Code Graph Analysis (5)
cmd/mocai/cli_constants.go (1)
cmd/mocai/utils.go (1)
SupportsANSI(9-22)
pkg/mocai/entities/company/countries/brazilian_company.go (1)
pkg/mocai/entities/company/countries/errors.go (1)
ErrNoCompanyNamesAvailable(11-11)
pkg/mocai/entities/cpf/generator.go (1)
pkg/mocai/entities/cpf/errors.go (1)
ErrInvalidCPF(6-6)
pkg/mocai/entities/person/generator.go (1)
pkg/mocai/entities/person/errors.go (3)
ErrNoFirstNames(10-10)ErrNoLastNames(11-11)ErrGeneratingPerson(9-9)
pkg/mocai/entities/phone/generator.go (1)
pkg/mocai/entities/phone/errors.go (2)
ErrNoAreaCodes(10-10)ErrGeneratingPhone(9-9)
🔇 Additional comments (22)
README.md (1)
66-66: Documentation correction aligns with code restructuring.The instruction correctly specifies navigating to the examples folder before running the example, which aligns with the restructuring of examples from a function to a standalone main program.
cmd/mocai/cli_constants.go (2)
1-1: Package reorganization is well-executed.The package name change from
constantstomocaiproperly reflects the restructuring of constants into the cmd/mocai package.
21-21: Function call correctly updated for same-package access.Removing the
mocai.prefix is appropriate sinceSupportsANSI()is now in the same package (available incmd/mocai/utils.go).docs/localization/pt/README-PT.md (1)
64-64: Portuguese documentation properly synchronized with main README.The instruction correctly specifies navigating to the examples folder, maintaining consistency with the main README documentation and the code restructuring.
examples/main.go (4)
1-1: Excellent restructuring to standalone executable.Converting from
examplespackage tomainpackage makes the example code self-contained and easier to run, aligning with the updated documentation.
6-6: Import path correctly updated for package reorganization.The import path change from
pkg/mocai/constantstocmd/mocaiproperly reflects the restructuring where constants were moved to the cmd/mocai package.
17-17: Function rename to main creates proper entry point.Renaming
GenerateMockExampletomainestablishes the proper entry point for the standalone executable, eliminating the need for a separate main.go file at the repository root.
64-66: Constant references properly updated for new package structure.The constants are now correctly accessed with the
mocai.prefix, reflecting their relocation to the cmd/mocai package. This maintains consistency with the package reorganization.Also applies to: 95-95
pkg/mocai/entities/national_id/countries/brazilian_national_id.go (1)
27-27: LGTM! Good formatting improvements.The added blank lines improve code readability by logically separating different sections within the functions.
Also applies to: 69-69, 77-77
pkg/mocai/entities/company/countries/errors.go (1)
11-11: LGTM! Proper error variable definition.Adding
ErrNoCompanyNamesAvailablefollows Go best practices by centralizing error definitions and using typed error variables instead of inline error creation.pkg/mocai/entities/cpf/generator.go (1)
36-36: LGTM! Improved error handling consistency.Returning the predefined
ErrInvalidCPFerror variable instead of creating a new error inline follows Go best practices and maintains consistency with the broader error handling refactoring.pkg/mocai/entities/vote_registration/countries/brazilian_vote_registration.go (1)
58-62: LGTM! Good code simplification.Removing the intermediate variable and returning the struct directly makes the code more concise while maintaining the same functionality.
pkg/mocai/entities/company/countries/brazilian_company.go (1)
29-29: LGTM - Proper use of predefined error variable.The change correctly replaces inline error creation with the predefined
ErrNoCompanyNamesAvailableerror variable, which follows Go best practices for error handling.pkg/mocai/entities/person/generator.go (3)
35-35: LGTM - Consistent use of predefined error variables.The changes correctly replace inline error creation with predefined error variables (
ErrNoFirstNames,ErrNoLastNames), which improves error handling consistency and follows Go best practices.Also applies to: 39-39
62-62: LGTM - Proper error variable usage in formatted error.The change correctly uses the predefined
ErrGeneratingPersonerror variable in the formatted error message, maintaining consistency with the error handling refactoring.
65-72: LGTM - Simplified return statement structure.The direct return of the struct pointer and nil error is cleaner and more idiomatic than assigning to a variable first.
pkg/mocai/entities/phone/generator.go (2)
40-40: LGTM - Proper error variable usage.The direct use of
ErrGeneratingPhoneinfmt.Errorfis correct and consistent with Go conventions.
43-46: LGTM - Simplified return statement structure.The direct return of the struct pointer and nil error is cleaner and more idiomatic than assigning to a variable first.
pkg/mocai/entities/phone/errors.go (2)
3-3: LGTM - Required import for error variable definitions.The
errorsimport is correctly added to support the error variable definitions usingerrors.New().
8-11: LGTM - Proper conversion from string constants to error variables.The conversion from string constants to typed error variables using
errors.New()follows Go best practices and enables better error handling, comparison, and wrapping.pkg/mocai/entities/person/errors.go (2)
3-3: LGTM - Required import for error variable definitions.The
errorsimport is correctly added to support the error variable definitions usingerrors.New().
8-12: LGTM - Proper conversion from string constants to error variables.The conversion from string constants to typed error variables using
errors.New()follows Go best practices and is consistent with similar changes in other entity packages.
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
pkg/mocai/entities/gender/gender.go (1)
32-32: Simplify pointer creation for better readability.The current pointer conversion is functional but could be more readable.
Consider this cleaner approach:
- return (*Gender)(&genderStr), nil + gender := Gender(genderStr) + return &gender, nildocs/localization/pt/README-PT.md (1)
39-54: Fix formatting: Replace hard tabs with spaces.The code blocks contain hard tabs that should be replaced with spaces for consistent formatting.
- // specific - translations.SetLanguage("ptbr") - - addr, err := address.GenerateAddress() - if err != nil { - return err - } - - addr.Street // retorna o nome da rua + // specific + translations.SetLanguage("ptbr") + + addr, err := address.GenerateAddress() + if err != nil { + return err + } + + addr.Street // retorna o nome da ruaApply similar spacing fixes to the mocker example block as well.
README.md (1)
41-56: Fix formatting: Replace hard tabs with spaces.The code blocks use hard tabs instead of spaces, which should be standardized for consistent formatting.
- // specific - translations.SetLanguage("ptbr") - - addr, err := address.GenerateAddress() - if err != nil { - return err - } - - addr.Street // returns street name + // specific + translations.SetLanguage("ptbr") + + addr, err := address.GenerateAddress() + if err != nil { + return err + } + + addr.Street // returns street nameApply the same spacing fix to the mocker example block.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
README.md(1 hunks)docs/localization/pt/README-PT.md(1 hunks)examples/mocker/main.go(1 hunks)examples/specific/main.go(4 hunks)pkg/mocai/entities/address/generator.go(1 hunks)pkg/mocai/entities/gender/gender.go(2 hunks)pkg/mocai/entities/person/generator.go(3 hunks)pkg/mocai/mocker.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- pkg/mocai/entities/address/generator.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/mocai/entities/person/generator.go
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
examples/mocker/main.go (3)
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
pkg/mocai/entities/gender/gender.go (2)
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
examples/specific/main.go (3)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
pkg/mocai/mocker.go (3)
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
README.md (3)
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
docs/localization/pt/README-PT.md (3)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
🧬 Code Graph Analysis (3)
examples/mocker/main.go (5)
cmd/mocai/cli_constants.go (3)
HeaderMain(14-14)SubHeader(15-15)Footer(16-16)pkg/mocai/mocker.go (1)
NewMocker(21-31)pkg/mocai/entities/person/generator.go (1)
Person(14-21)pkg/mocai/entities/address/generator.go (1)
Address(12-19)pkg/mocai/entities/phone/generator.go (1)
Phone(12-15)
pkg/mocai/entities/gender/gender.go (2)
pkg/mocai/translations/translations.go (2)
GetLanguage(47-51)Get(54-67)pkg/mocai/entities/gender/errors.go (1)
ErrNoGenders(9-9)
examples/specific/main.go (2)
cmd/mocai/cli_constants.go (3)
HeaderMain(14-14)SubHeader(15-15)Footer(16-16)pkg/mocai/entities/gender/gender.go (1)
Gender(10-10)
🪛 LanguageTool
README.md
[uncategorized] ~61-~61: Loose punctuation mark.
Context: ...y, organized by approach: - specific/: Examples using direct calls to each of ...
(UNLIKELY_OPENING_PUNCTUATION)
[style] ~61-~61: In American English, abbreviations like “etc.” require a period.
Context: ...le entities (e.g., phone.GeneratePhone, etc). - mocker/: Example using a main en...
(ETC_PERIOD)
[uncategorized] ~63-~63: Loose punctuation mark.
Context: ... phone.GeneratePhone, etc). - mocker/: Example using a main entry point `mocai...
(UNLIKELY_OPENING_PUNCTUATION)
docs/localization/pt/README-PT.md
[uncategorized] ~60-~60: Sinal de pontuação isolado.
Context: ...rganizados por abordagem: - specific/: Exemplos usando as funções diretas de c...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~60-~60: Se é uma abreviatura, falta um ponto. Se for uma expressão, coloque entre aspas.
Context: ...ckável do Mocaí (phone.GeneratePhone, etc). - mocker/: Exemplo usando um ponto...
(ABREVIATIONS_PUNCTUATION)
[uncategorized] ~62-~62: Sinal de pontuação isolado.
Context: ...phone.GeneratePhone, etc). - mocker/`: Exemplo usando um ponto de entrada prin...
(UNLIKELY_OPENING_PUNCTUATION)
🪛 markdownlint-cli2 (0.17.2)
README.md
41-41: Hard tabs
Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs
Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs
Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs
Column: 1
(MD010, no-hard-tabs)
45-45: Hard tabs
Column: 1
(MD010, no-hard-tabs)
46-46: Hard tabs
Column: 1
(MD010, no-hard-tabs)
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
49-49: Hard tabs
Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs
Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs
Column: 1
(MD010, no-hard-tabs)
55-55: Hard tabs
Column: 1
(MD010, no-hard-tabs)
56-56: Hard tabs
Column: 1
(MD010, no-hard-tabs)
docs/localization/pt/README-PT.md
39-39: Hard tabs
Column: 1
(MD010, no-hard-tabs)
40-40: Hard tabs
Column: 1
(MD010, no-hard-tabs)
41-41: Hard tabs
Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs
Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs
Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs
Column: 1
(MD010, no-hard-tabs)
45-45: Hard tabs
Column: 1
(MD010, no-hard-tabs)
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
51-51: Hard tabs
Column: 1
(MD010, no-hard-tabs)
52-52: Hard tabs
Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs
Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (13)
pkg/mocai/entities/gender/gender.go (3)
4-4: LGTM: Import change aligns with error handling update.The switch from
errorstofmtpackage is consistent with usingfmt.Errorffor formatted error messages.
29-29: LGTM: Improved error formatting.Using
fmt.Errorfwith formatted strings provides better error context than simple string concatenation.
24-24: *All GenerateRandomGender calls handle the new Gender return typeBoth instances of GenerateRandomGender have been updated to use the pointer signature correctly:
- pkg/mocai/mocker.go: Mocker.Gender now assigns and returns
*gender.Gender.- pkg/mocai/entities/person/generator.go: the generator captures
*Genderand propagates the pointer.No further changes needed.
examples/specific/main.go (5)
1-1: LGTM: Package change enables standalone execution.Converting from
package examplestopackage mainallows this example to run independently.
6-6: LGTM: Import alias provides clear namespace separation.The
clialias for the CLI constants package improves code readability.
17-17: LGTM: Function renamed to standard main entry point.Converting
GenerateMockExampletomainfollows Go conventions for executable programs.
64-66: LGTM: Updated constants references.The CLI constants are now properly referenced with the
clinamespace.
68-68: LGTM: Gender dereference correctly handles pointer type.The
*p.Genderdereference is consistent with the updatedGenderfield being a pointer type in the Person struct.examples/mocker/main.go (1)
1-33: LGTM: Excellent demonstration of the new Mocker interface.This example clearly showcases the fluent interface approach with the new
mocai.NewMockerstruct. The code is well-structured with helpful comments explaining the usage patterns and demonstrates proper access to entity fields.docs/localization/pt/README-PT.md (2)
38-56: LGTM: Documentation accurately reflects new API.The updated examples clearly demonstrate both the direct entity usage and the new Mocker interface approaches.
58-67: LGTM: Clear explanation of example organization.The explanation of the
specific/andmocker/directories helps users understand the different approaches available.README.md (2)
40-58: LGTM: Examples accurately demonstrate both API approaches.The documentation effectively showcases both the direct entity usage and the new fluent Mocker interface.
59-68: LGTM: Clear structure explanation for examples.The explanation of the reorganized examples directory helps users choose the appropriate approach for their needs.
| func (m *Mocker) Address() *address.Address { | ||
| a, _ := address.GenerateAddress() | ||
|
|
||
| return a | ||
| } | ||
|
|
||
| func (m *Mocker) Certificate() *certificate.Certificate { | ||
| c, _ := certificate.GenerateCertificate(false) | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| func (m *Mocker) Company() *company.Company { | ||
| c, _ := company.GenerateCompany(false) | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| func (m *Mocker) Gender() *gender.Gender { | ||
| g, _ := gender.GenerateRandomGender() | ||
|
|
||
| return g | ||
| } | ||
|
|
||
| func (m *Mocker) NationalID() *national_id.NationalID { | ||
| n, _ := national_id.GenerateNationalID(false) | ||
|
|
||
| return n | ||
| } | ||
|
|
||
| func (m *Mocker) Person() *person.Person { | ||
| p, _ := person.GeneratePerson() | ||
|
|
||
| return p | ||
| } | ||
|
|
||
| func (m *Mocker) Phone() *phone.Phone { | ||
| p, _ := phone.GeneratePhone() | ||
|
|
||
| return p | ||
| } | ||
|
|
||
| func (m *Mocker) VoteRegistration() *vote_registration.VoteRegistration { | ||
| v, _ := vote_registration.GenerateVoteRegistration(false) | ||
|
|
||
| return v | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Consider returning errors from entity generation methods.
All entity generation methods silently ignore errors, which could result in nil pointers being returned when generation fails. This makes debugging difficult and could lead to panics in user code.
Consider one of these approaches:
Option 1: Return errors to caller (recommended)
-func (m *Mocker) Address() *address.Address {
+func (m *Mocker) Address() (*address.Address, error) {
- a, _ := address.GenerateAddress()
+ return address.GenerateAddress()
-
- return a
}Option 2: Use panic for critical failures
func (m *Mocker) Address() *address.Address {
- a, _ := address.GenerateAddress()
+ a, err := address.GenerateAddress()
+ if err != nil {
+ panic(fmt.Sprintf("failed to generate address: %v", err))
+ }
return a
}Option 3: Log errors and return nil
func (m *Mocker) Address() *address.Address {
- a, _ := address.GenerateAddress()
+ a, err := address.GenerateAddress()
+ if err != nil {
+ fmt.Printf("warning: failed to generate address: %v\n", err)
+ return nil
+ }
return a
}The first option provides the most flexibility for error handling.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (m *Mocker) Address() *address.Address { | |
| a, _ := address.GenerateAddress() | |
| return a | |
| } | |
| func (m *Mocker) Certificate() *certificate.Certificate { | |
| c, _ := certificate.GenerateCertificate(false) | |
| return c | |
| } | |
| func (m *Mocker) Company() *company.Company { | |
| c, _ := company.GenerateCompany(false) | |
| return c | |
| } | |
| func (m *Mocker) Gender() *gender.Gender { | |
| g, _ := gender.GenerateRandomGender() | |
| return g | |
| } | |
| func (m *Mocker) NationalID() *national_id.NationalID { | |
| n, _ := national_id.GenerateNationalID(false) | |
| return n | |
| } | |
| func (m *Mocker) Person() *person.Person { | |
| p, _ := person.GeneratePerson() | |
| return p | |
| } | |
| func (m *Mocker) Phone() *phone.Phone { | |
| p, _ := phone.GeneratePhone() | |
| return p | |
| } | |
| func (m *Mocker) VoteRegistration() *vote_registration.VoteRegistration { | |
| v, _ := vote_registration.GenerateVoteRegistration(false) | |
| return v | |
| } | |
| func (m *Mocker) Address() (*address.Address, error) { | |
| return address.GenerateAddress() | |
| } |
🤖 Prompt for AI Agents
In pkg/mocai/mocker.go between lines 41 and 87, the entity generation methods
ignore errors and always return the generated object, risking nil pointer
dereferences if generation fails. Modify these methods to return both the
generated entity and an error, propagating the error to the caller. Update the
method signatures to include an error return value and handle the error from the
generation functions accordingly, returning nil and the error if generation
fails.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
docs/localization/pt/README-PT.md (3)
38-48: Substitute hard tabs with spaces in the code block
markdownlint(MD010) is flagging every line in this snippet because it starts with a tab. Tabs also bloat diffs and render inconsistently across tools.- // specific - translations.SetLanguage("ptbr") - - addr, err := address.GenerateAddress() - if err != nil { - log.Println(err) - } - - addr.Street // retorna o nome da rua +// specific +translations.SetLanguage("ptbr") + +addr, err := address.GenerateAddress() +if err != nil { + log.Println(err) +} + +addr.Street // retorna o nome da rua
50-59: Repeat-tab issue and missing import context
- Same MD010 complaint – replace tabs with spaces (see diff pattern above).
- Consider adding a minimal import stanza (even as a comment) so newcomers know which package provides
mocai.NewMocker.// import ( // "github.com/brazzcore/mocai" // )
62-66: Fix typo and punctuation in “Exemplos” section
- “comoo” → “como”.
- Add full stop after “etc.”.
- Keep the project name spelling consistent (
Mocaiis used elsewhere without the accent).-O diretório ***examples*** contém exemplos de comoo usar a biblioteca, organizados por abordagem: +O diretório ***examples*** contém exemplos de como usar a biblioteca, organizados por abordagem: -- `specific/`: Exemplos usando as funções diretas de cada entidade mockável do Mocaí (`phone.GeneratePhone`, etc). +- `specific/`: Exemplos usando as funções diretas de cada entidade mockável do Mocai (por exemplo, `phone.GeneratePhone`, etc.).README.md (3)
40-50: Replace leading tabs to comply with MD010Same formatting issue as in the PT README. Convert the indentation to spaces to silence markdownlint and keep rendering consistent.
- // specific - translations.SetLanguage("ptbr") - - addr, err := address.GenerateAddress() - if err != nil { - log.Println(err) - } - - addr.Street // returns street name +// specific +translations.SetLanguage("ptbr") + +addr, err := address.GenerateAddress() +if err != nil { + log.Println(err) +} + +addr.Street // returns street name
52-61: Repeat the space-for-tab fix & add import cueAs above, replace tabs with spaces and optionally include a commented import block to clarify where
mocai.NewMockercomes from for first-time readers.
63-67: Minor wording & punctuation clean-up in bullet listLanguageTool flags an isolated punctuation mark and a missing period after “etc”. Suggested tweak:
-- `specific/`: Examples using direct calls to each of Mocaí's mockable entities (e.g., phone.GeneratePhone, etc). +- `specific/`: Examples using direct calls to each of Mocai's mockable entities (e.g., `phone.GeneratePhone`, etc.).This also standardises the accentless “Mocai” spelling used elsewhere in the English docs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
README.md(1 hunks)docs/localization/pt/README-PT.md(1 hunks)examples/mocker/main.go(1 hunks)pkg/mocai/mocker.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/mocker/main.go
- pkg/mocai/mocker.go
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
README.md (3)
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
docs/localization/pt/README-PT.md (3)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
🪛 LanguageTool
README.md
[uncategorized] ~65-~65: Loose punctuation mark.
Context: ...y, organized by approach: - specific/: Examples using direct calls to each of ...
(UNLIKELY_OPENING_PUNCTUATION)
[style] ~65-~65: In American English, abbreviations like “etc.” require a period.
Context: ...le entities (e.g., phone.GeneratePhone, etc). - mocker/: Example using a main en...
(ETC_PERIOD)
[uncategorized] ~67-~67: Loose punctuation mark.
Context: ... phone.GeneratePhone, etc). - mocker/: Example using a main entry point `mocai...
(UNLIKELY_OPENING_PUNCTUATION)
docs/localization/pt/README-PT.md
[uncategorized] ~64-~64: Sinal de pontuação isolado.
Context: ...rganizados por abordagem: - specific/: Exemplos usando as funções diretas de c...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~64-~64: Se é uma abreviatura, falta um ponto. Se for uma expressão, coloque entre aspas.
Context: ...ckável do Mocaí (phone.GeneratePhone, etc). - mocker/: Exemplo usando um ponto...
(ABREVIATIONS_PUNCTUATION)
[uncategorized] ~66-~66: Sinal de pontuação isolado.
Context: ...phone.GeneratePhone, etc). - mocker/`: Exemplo usando um ponto de entrada prin...
(UNLIKELY_OPENING_PUNCTUATION)
🪛 markdownlint-cli2 (0.17.2)
README.md
41-41: Hard tabs
Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs
Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs
Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs
Column: 1
(MD010, no-hard-tabs)
45-45: Hard tabs
Column: 1
(MD010, no-hard-tabs)
46-46: Hard tabs
Column: 1
(MD010, no-hard-tabs)
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
49-49: Hard tabs
Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs
Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs
Column: 1
(MD010, no-hard-tabs)
55-55: Hard tabs
Column: 1
(MD010, no-hard-tabs)
56-56: Hard tabs
Column: 1
(MD010, no-hard-tabs)
57-57: Hard tabs
Column: 1
(MD010, no-hard-tabs)
58-58: Hard tabs
Column: 1
(MD010, no-hard-tabs)
59-59: Hard tabs
Column: 1
(MD010, no-hard-tabs)
60-60: Hard tabs
Column: 1
(MD010, no-hard-tabs)
docs/localization/pt/README-PT.md
39-39: Hard tabs
Column: 1
(MD010, no-hard-tabs)
40-40: Hard tabs
Column: 1
(MD010, no-hard-tabs)
41-41: Hard tabs
Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs
Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs
Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs
Column: 1
(MD010, no-hard-tabs)
45-45: Hard tabs
Column: 1
(MD010, no-hard-tabs)
47-47: Hard tabs
Column: 1
(MD010, no-hard-tabs)
51-51: Hard tabs
Column: 1
(MD010, no-hard-tabs)
52-52: Hard tabs
Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs
Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs
Column: 1
(MD010, no-hard-tabs)
55-55: Hard tabs
Column: 1
(MD010, no-hard-tabs)
56-56: Hard tabs
Column: 1
(MD010, no-hard-tabs)
57-57: Hard tabs
Column: 1
(MD010, no-hard-tabs)
58-58: Hard tabs
Column: 1
(MD010, no-hard-tabs)
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
docs/localization/pt/README-PT.md (2)
38-48: Code sample is incomplete – missingpackage, imports andtranslationsoriginThe snippet compiles only after the user manually wraps it in a
mainpackage and adds the proper imports (log,github.com/brazzcore/mocai/pkg/mocai/address,github.com/brazzcore/mocai/pkg/mocai/translations).
Providing a minimal self-contained example avoids frustration for copy-paste readers.```go -// specific +package main + +import ( + "log" + "github.com/brazzcore/mocai/pkg/mocai/address" + "github.com/brazzcore/mocai/pkg/mocai/translations" +) + +func main() { + // specific translations.SetLanguage("ptbr") addr, err := address.GenerateAddress() if err != nil { log.Println(err) } addr.Street // retorna o nome da rua +}
62-66: Typo and punctuation in examples section
comoo➜como, and add the missing full stop after “etc” for consistent Portuguese punctuation.-O diretório ***examples*** contém exemplos de comoo usar a biblioteca, organizados por abordagem: +O diretório ***examples*** contém exemplos de como usar a biblioteca, organizados por abordagem: -- `specific/`: Exemplos usando as funções diretas de cada entidade mockável do Mocaí (`phone.GeneratePhone`, etc). +- `specific/`: Exemplos usando as funções diretas de cada entidade mockável do Mocaí (`phone.GeneratePhone`, etc.).README.md (2)
40-50: Provide self-contained Go example (imports +main)Same concern as in the PT README – readers cannot run this snippet as-is. Including the minimal scaffolding improves developer experience.
```go -// specific +package main + +import ( + "log" + "github.com/brazzcore/mocai/pkg/mocai/address" + "github.com/brazzcore/mocai/pkg/mocai/translations" +) + +func main() { + // specific translations.SetLanguage("ptbr") addr, err := address.GenerateAddress() if err != nil { log.Println(err) } addr.Street // returns street name +}
63-67: Minor wording & punctuation fixes in bullet listAdd period after “etc” (per English style) and drop the leading dash duplication picked up by LanguageTool.
-The ***examples*** folder contains samples of how to use the library, organized by approach: +The ***examples*** folder contains samples of how to use the library, organized by approach: -- `specific/`: Examples using direct calls to each of Mocaí's mockable entities (e.g., phone.GeneratePhone, etc). +- `specific/`: Examples using direct calls to each of Mocaí's mockable entities (e.g., phone.GeneratePhone, etc.).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md(1 hunks)docs/localization/pt/README-PT.md(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
README.md (3)
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
Learnt from: wellfernandes
PR: brazzcore/mocai#39
File: pkg/mocai/entities/certificate/countries/brazilian_certificates.go:3-7
Timestamp: 2025-03-21T14:36:42.742Z
Learning: In the mocai project, Go version higher than 1.20 is being used, which means the global random number generator (math/rand) is automatically seeded and rand.Seed() is not needed.
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
docs/localization/pt/README-PT.md (2)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-11T21:56:28.660Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
Learnt from: wellfernandes
PR: brazzcore/mocai#44
File: pkg/mocai/entities/national_id/countries/brazilian_national_id.go:10-10
Timestamp: 2025-04-03T19:13:54.833Z
Learning: For the mocai project, using math/rand is acceptable for generating mock data (like national IDs) since the data is fictitious and not intended for security-sensitive purposes.
🪛 LanguageTool
README.md
[uncategorized] ~65-~65: Loose punctuation mark.
Context: ...y, organized by approach: - specific/: Examples using direct calls to each of ...
(UNLIKELY_OPENING_PUNCTUATION)
[style] ~65-~65: In American English, abbreviations like “etc.” require a period.
Context: ...le entities (e.g., phone.GeneratePhone, etc). - mocker/: Example using a main en...
(ETC_PERIOD)
[uncategorized] ~67-~67: Loose punctuation mark.
Context: ... phone.GeneratePhone, etc). - mocker/: Example using a main entry point `mocai...
(UNLIKELY_OPENING_PUNCTUATION)
docs/localization/pt/README-PT.md
[uncategorized] ~64-~64: Sinal de pontuação isolado.
Context: ...rganizados por abordagem: - specific/: Exemplos usando as funções diretas de c...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~64-~64: Se é uma abreviatura, falta um ponto. Se for uma expressão, coloque entre aspas.
Context: ...ckável do Mocaí (phone.GeneratePhone, etc). - mocker/: Exemplo usando um ponto...
(ABREVIATIONS_PUNCTUATION)
[uncategorized] ~66-~66: Sinal de pontuação isolado.
Context: ...phone.GeneratePhone, etc). - mocker/`: Exemplo usando um ponto de entrada prin...
(UNLIKELY_OPENING_PUNCTUATION)
cmd/mocai/cli_constants.go
Outdated
| import ( | ||
| "github.com/brazzcore/mocai/pkg/mocai" | ||
| ) | ||
| package mocai |
There was a problem hiding this comment.
As coisas dentro de cmd são sempre package main e não pode ser importadas em outros lugares
There was a problem hiding this comment.
Perfeito! Criei um diretório internal pra isso!
#47
Summary by CodeRabbit
New Features
Documentation
Refactor
Tests
Chores