From 38f333803382059a5f35ce89d5788721dbbb8730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Fri, 28 Jun 2024 00:49:19 +0800 Subject: [PATCH] feat: optimize lint --- README.md | 14 ++++---- README_zh.md | 14 ++++---- cache/memory.go | 20 +++++------ console/console/list_command.go | 8 ++--- console/console/stubs.go | 8 ++--- database/console/migrate_creator.go | 4 +-- database/console/migrate_make_command.go | 2 +- http/console/stubs.go | 4 +-- http/context.go | 1 - mail/job.go | 4 +-- queue/console/job_stubs.go | 4 +-- queue/task_test.go | 4 +-- schedule/event.go | 42 ++++++++++++------------ validation/console/stubs.go | 6 ++-- 14 files changed, 67 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index a57137529..9d59995ae 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ Example [https://github.com/goravel/example](https://github.com/goravel/example) ## Main Function -| | | | | | -| ---------- | -------------- | -------------- | -------------- | -------------- | -| [Config](https://www.goravel.dev/getting-started/configuration.html) | [Http](https://www.goravel.dev/the-basics/routing.html) | [Authentication](https://www.goravel.dev/security/authentication.html) | [Authorization](https://www.goravel.dev/security/authorization.html) | [Orm](https://www.goravel.dev/orm/getting-started.html) | -| [Migrate](https://www.goravel.dev/orm/migrations.html) | [Logger](https://www.goravel.dev/the-basics/logging.html) | [Cache](https://www.goravel.dev/digging-deeper/cache.html) | [Grpc](https://www.goravel.dev/the-basics/grpc.html) | [Artisan Console](https://www.goravel.dev/digging-deeper/artisan-console.html) | -| [Task Scheduling](https://www.goravel.dev/digging-deeper/task-scheduling.html) | [Queue](https://www.goravel.dev/digging-deeper/queues.html) | [Event](https://www.goravel.dev/digging-deeper/event.html) | [FileStorage](https://www.goravel.dev/digging-deeper/filesystem.html) | [Mail](https://www.goravel.dev/digging-deeper/mail.html) | -| [Validation](https://www.goravel.dev/the-basics/validation.html) | [Mock](https://www.goravel.dev/testing/mock.html) | [Hash](https://www.goravel.dev/security/hashing.html) | [Crypt](https://www.goravel.dev/security/encryption.html) | [Carbon](https://www.goravel.dev/digging-deeper/helpers.html) | -| [Package Development](https://www.goravel.dev/digging-deeper/package-development.html) | [Testing](https://www.goravel.dev/testing/getting-started.html) | [Localization](https://www.goravel.dev/digging-deeper/localization.html) | [Session](https://www.goravel.dev/the-basics/session.html) | | +| | | | | | +|----------------------------------------------------------------------------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------------|--------------------------------------------------------------------------------| +| [Config](https://www.goravel.dev/getting-started/configuration.html) | [Http](https://www.goravel.dev/the-basics/routing.html) | [Authentication](https://www.goravel.dev/security/authentication.html) | [Authorization](https://www.goravel.dev/security/authorization.html) | [Orm](https://www.goravel.dev/orm/getting-started.html) | +| [Migrate](https://www.goravel.dev/orm/migrations.html) | [Logger](https://www.goravel.dev/the-basics/logging.html) | [Cache](https://www.goravel.dev/digging-deeper/cache.html) | [Grpc](https://www.goravel.dev/the-basics/grpc.html) | [Artisan Console](https://www.goravel.dev/digging-deeper/artisan-console.html) | +| [Task Scheduling](https://www.goravel.dev/digging-deeper/task-scheduling.html) | [Queue](https://www.goravel.dev/digging-deeper/queues.html) | [Event](https://www.goravel.dev/digging-deeper/event.html) | [FileStorage](https://www.goravel.dev/digging-deeper/filesystem.html) | [Mail](https://www.goravel.dev/digging-deeper/mail.html) | +| [Validation](https://www.goravel.dev/the-basics/validation.html) | [Mock](https://www.goravel.dev/testing/mock.html) | [Hash](https://www.goravel.dev/security/hashing.html) | [Crypt](https://www.goravel.dev/security/encryption.html) | [Carbon](https://www.goravel.dev/digging-deeper/helpers.html) | +| [Package Development](https://www.goravel.dev/digging-deeper/package-development.html) | [Testing](https://www.goravel.dev/testing/getting-started.html) | [Localization](https://www.goravel.dev/digging-deeper/localization.html) | [Session](https://www.goravel.dev/the-basics/session.html) | | ## Roadmap diff --git a/README_zh.md b/README_zh.md index ffa10ad28..d1673110a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -33,13 +33,13 @@ Laravel! ## 主要功能 -| | | | | | -| ---------- | -------------- | -------------- | -------------- | -------------- | -| [自定义配置](https://www.goravel.dev/zh/getting-started/configuration.html) | [HTTP 服务](https://www.goravel.dev/zh/the-basics/routing.html) | [用户认证](https://www.goravel.dev/zh/security/authentication.html) | [用户授权](https://www.goravel.dev/zh/security/authorization.html) | [数据库 ORM](https://www.goravel.dev/zh/orm/getting-started.html) | -| [数据库迁移](https://www.goravel.dev/zh/orm/migrations.html) | [日志](https://www.goravel.dev/zh/the-basics/logging.html) | [缓存](https://www.goravel.dev/zh/digging-deeper/cache.html) | [Grpc](https://www.goravel.dev/zh/the-basics/grpc.html) | [Artisan 命令行](https://www.goravel.dev/zh/digging-deeper/artisan-console.html) | -| [任务调度](https://www.goravel.dev/zh/digging-deeper/task-scheduling.html) | [队列](https://www.goravel.dev/zh/digging-deeper/queues.html) | [事件系统](https://www.goravel.dev/zh/digging-deeper/event.html) | [文件存储](https://www.goravel.dev/zh/digging-deeper/filesystem.html) | [邮件](https://www.goravel.dev/zh/digging-deeper/mail.html) | -| [表单验证](https://www.goravel.dev/zh/the-basics/validation.html) | [Mock](https://www.goravel.dev/zh/digging-deeper/mock.html) | [Hash](https://www.goravel.dev/zh/security/hashing.html) | [Crypt](https://www.goravel.dev/zh/security/encryption.html) | [Carbon](https://www.goravel.dev/zh/digging-deeper/helpers.html) | -| [扩展包开发](https://www.goravel.dev/zh/digging-deeper/package-development.html) | [测试](https://www.goravel.dev/zh/testing/getting-started.html) | [本地化](https://www.goravel.dev/zh/digging-deeper/localization.html) | [Session](https://www.goravel.dev/zh/the-basics/session.html) | | +| | | | | | +|-----------------------------------------------------------------------------|---------------------------------------------------------------|--------------------------------------------------------------------|-------------------------------------------------------------------|-------------------------------------------------------------------------------| +| [自定义配置](https://www.goravel.dev/zh/getting-started/configuration.html) | [HTTP 服务](https://www.goravel.dev/zh/the-basics/routing.html) | [用户认证](https://www.goravel.dev/zh/security/authentication.html) | [用户授权](https://www.goravel.dev/zh/security/authorization.html) | [数据库 ORM](https://www.goravel.dev/zh/orm/getting-started.html) | +| [数据库迁移](https://www.goravel.dev/zh/orm/migrations.html) | [日志](https://www.goravel.dev/zh/the-basics/logging.html) | [缓存](https://www.goravel.dev/zh/digging-deeper/cache.html) | [Grpc](https://www.goravel.dev/zh/the-basics/grpc.html) | [Artisan 命令行](https://www.goravel.dev/zh/digging-deeper/artisan-console.html) | +| [任务调度](https://www.goravel.dev/zh/digging-deeper/task-scheduling.html) | [队列](https://www.goravel.dev/zh/digging-deeper/queues.html) | [事件系统](https://www.goravel.dev/zh/digging-deeper/event.html) | [文件存储](https://www.goravel.dev/zh/digging-deeper/filesystem.html) | [邮件](https://www.goravel.dev/zh/digging-deeper/mail.html) | +| [表单验证](https://www.goravel.dev/zh/the-basics/validation.html) | [Mock](https://www.goravel.dev/zh/digging-deeper/mock.html) | [Hash](https://www.goravel.dev/zh/security/hashing.html) | [Crypt](https://www.goravel.dev/zh/security/encryption.html) | [Carbon](https://www.goravel.dev/zh/digging-deeper/helpers.html) | +| [扩展包开发](https://www.goravel.dev/zh/digging-deeper/package-development.html) | [测试](https://www.goravel.dev/zh/testing/getting-started.html) | [本地化](https://www.goravel.dev/zh/digging-deeper/localization.html) | [Session](https://www.goravel.dev/zh/the-basics/session.html) | | ## 路线图 diff --git a/cache/memory.go b/cache/memory.go index dcf022684..28dd943e0 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -26,7 +26,7 @@ func NewMemory(config config.Config) (*Memory, error) { }, nil } -//Add Driver an item in the cache if the key does not exist. +// Add Driver an item in the cache if the key does not exist. func (r *Memory) Add(key string, value any, t time.Duration) bool { if t == NoExpiration { t = cache.NoExpiration @@ -46,7 +46,7 @@ func (r *Memory) Decrement(key string, value ...int) (int, error) { return r.instance.DecrementInt(r.key(key), value[0]) } -//Forever Driver an item in the cache indefinitely. +// Forever Driver an item in the cache indefinitely. func (r *Memory) Forever(key string, value any) bool { if err := r.Put(key, value, cache.NoExpiration); err != nil { return false @@ -55,21 +55,21 @@ func (r *Memory) Forever(key string, value any) bool { return true } -//Forget Remove an item from the cache. +// Forget Remove an item from the cache. func (r *Memory) Forget(key string) bool { r.instance.Delete(r.key(key)) return true } -//Flush Remove all items from the cache. +// Flush Remove all items from the cache. func (r *Memory) Flush() bool { r.instance.Flush() return true } -//Get Retrieve an item from the cache by key. +// Get Retrieve an item from the cache by key. func (r *Memory) Get(key string, def ...any) any { val, exist := r.instance.Get(r.key(key)) if exist { @@ -120,7 +120,7 @@ func (r *Memory) GetString(key string, def ...string) string { return cast.ToString(r.Get(key, def[0])) } -//Has Check an item exists in the cache. +// Has Check an item exists in the cache. func (r *Memory) Has(key string) bool { _, exist := r.instance.Get(r.key(key)) @@ -140,7 +140,7 @@ func (r *Memory) Lock(key string, t ...time.Duration) contractscache.Lock { return NewLock(r, key, t...) } -//Pull Retrieve an item from the cache and delete it. +// Pull Retrieve an item from the cache and delete it. func (r *Memory) Pull(key string, def ...any) any { var res any if len(def) == 0 { @@ -153,14 +153,14 @@ func (r *Memory) Pull(key string, def ...any) any { return res } -//Put Driver an item in the cache for a given number of seconds. +// Put Driver an item in the cache for a given number of seconds. func (r *Memory) Put(key string, value any, t time.Duration) error { r.instance.Set(r.key(key), value, t) return nil } -//Remember Get an item from the cache, or execute the given Closure and store the result. +// Remember Get an item from the cache, or execute the given Closure and store the result. func (r *Memory) Remember(key string, seconds time.Duration, callback func() (any, error)) (any, error) { val := r.Get(key, nil) if val != nil { @@ -180,7 +180,7 @@ func (r *Memory) Remember(key string, seconds time.Duration, callback func() (an return val, nil } -//RememberForever Get an item from the cache, or execute the given Closure and store the result forever. +// RememberForever Get an item from the cache, or execute the given Closure and store the result forever. func (r *Memory) RememberForever(key string, callback func() (any, error)) (any, error) { val := r.Get(key, nil) if val != nil { diff --git a/console/console/list_command.go b/console/console/list_command.go index db003658b..14d9ed6fc 100644 --- a/console/console/list_command.go +++ b/console/console/list_command.go @@ -15,22 +15,22 @@ func NewListCommand(artisan console.Artisan) *ListCommand { } } -//Signature The name and signature of the console command. +// Signature The name and signature of the console command. func (receiver *ListCommand) Signature() string { return "list" } -//Description The console command description. +// Description The console command description. func (receiver *ListCommand) Description() string { return "List commands" } -//Extend The console command extend. +// Extend The console command extend. func (receiver *ListCommand) Extend() command.Extend { return command.Extend{} } -//Handle Execute the console command. +// Handle Execute the console command. func (receiver *ListCommand) Handle(ctx console.Context) error { receiver.artisan.Call("--help") diff --git a/console/console/stubs.go b/console/console/stubs.go index da864b138..50d86bbee 100644 --- a/console/console/stubs.go +++ b/console/console/stubs.go @@ -14,22 +14,22 @@ import ( type DummyCommand struct { } -//Signature The name and signature of the console command. +// Signature The name and signature of the console command. func (receiver *DummyCommand) Signature() string { return "command:name" } -//Description The console command description. +// Description The console command description. func (receiver *DummyCommand) Description() string { return "Command description" } -//Extend The console command extend. +// Extend The console command extend. func (receiver *DummyCommand) Extend() command.Extend { return command.Extend{} } -//Handle Execute the console command. +// Handle Execute the console command. func (receiver *DummyCommand) Handle(ctx console.Context) error { return nil diff --git a/database/console/migrate_creator.go b/database/console/migrate_creator.go index ed57400fd..e1b7f68d6 100644 --- a/database/console/migrate_creator.go +++ b/database/console/migrate_creator.go @@ -28,12 +28,12 @@ func (receiver MigrateCreator) Create(name string, table string, create bool) er // various place-holders, save the file, and run the post create event. upStub, downStub := receiver.getStub(table, create) - //Create the up.sql file. + // Create the up.sql file. if err := file.Create(receiver.getPath(name, "up"), receiver.populateStub(upStub, table)); err != nil { return err } - //Create the down.sql file. + // Create the down.sql file. if err := file.Create(receiver.getPath(name, "down"), receiver.populateStub(downStub, table)); err != nil { return err } diff --git a/database/console/migrate_make_command.go b/database/console/migrate_make_command.go index 462e5baf7..52b45059e 100644 --- a/database/console/migrate_make_command.go +++ b/database/console/migrate_make_command.go @@ -61,7 +61,7 @@ func (receiver *MigrateMakeCommand) Handle(ctx console.Context) error { // of creating migrations that create new tables for the application. table, create := TableGuesser{}.Guess(name) - //Write the migration file to disk. + // Write the migration file to disk. migrateCreator := NewMigrateCreator(receiver.config) if err := migrateCreator.Create(name, table, create); err != nil { return err diff --git a/http/console/stubs.go b/http/console/stubs.go index 1c622452c..5120421b7 100644 --- a/http/console/stubs.go +++ b/http/console/stubs.go @@ -45,12 +45,12 @@ import ( ) type DummyController struct { - //Dependent services + // Dependent services } func NewDummyController() *DummyController { return &DummyController{ - //Inject services + // Inject services } } diff --git a/http/context.go b/http/context.go index 9ba1658b6..07120b8b8 100644 --- a/http/context.go +++ b/http/context.go @@ -38,4 +38,3 @@ func (r *Context) Request() http.ContextRequest { func (r *Context) Response() http.ContextResponse { return nil } - diff --git a/mail/job.go b/mail/job.go index b42ea27d9..90a576bad 100644 --- a/mail/job.go +++ b/mail/job.go @@ -14,12 +14,12 @@ func NewSendMailJob(config config.Config) *SendMailJob { } } -//Signature The name and signature of the job. +// Signature The name and signature of the job. func (r *SendMailJob) Signature() string { return "goravel_send_mail_job" } -//Handle Execute the job. +// Handle Execute the job. func (r *SendMailJob) Handle(args ...any) error { return SendMail(r.config, args[0].(string), args[1].(string), args[2].(string), args[3].(string), args[4].([]string), args[5].([]string), args[6].([]string), args[7].([]string)) } diff --git a/queue/console/job_stubs.go b/queue/console/job_stubs.go index 0d4b5e92b..a834da8d4 100644 --- a/queue/console/job_stubs.go +++ b/queue/console/job_stubs.go @@ -10,12 +10,12 @@ func (receiver JobStubs) Job() string { type DummyJob struct { } -//Signature The name and signature of the job. +// Signature The name and signature of the job. func (receiver *DummyJob) Signature() string { return "DummyName" } -//Handle Execute the job. +// Handle Execute the job. func (receiver *DummyJob) Handle(args ...any) error { return nil } diff --git a/queue/task_test.go b/queue/task_test.go index 343a678e4..b95ea731b 100644 --- a/queue/task_test.go +++ b/queue/task_test.go @@ -13,12 +13,12 @@ import ( type Test struct { } -//Signature The name and signature of the job. +// Signature The name and signature of the job. func (receiver *Test) Signature() string { return "test" } -//Handle Execute the job. +// Handle Execute the job. func (receiver *Test) Handle(args ...any) error { return file.Create("test.txt", args[0].(string)) } diff --git a/schedule/event.go b/schedule/event.go index cd716a46c..f3c37f94d 100644 --- a/schedule/event.go +++ b/schedule/event.go @@ -24,26 +24,26 @@ func NewCommandEvent(command string) *Event { return &Event{command: command, name: command} } -//At Schedule the command at a given time. +// At Schedule the command at a given time. func (receiver *Event) At(time string) schedule.Event { return receiver.DailyAt(time) } -//Cron The Cron expression representing the event's frequency. +// Cron The Cron expression representing the event's frequency. func (receiver *Event) Cron(expression string) schedule.Event { receiver.cron = expression return receiver } -//Daily Schedule the event to run daily. +// Daily Schedule the event to run daily. func (receiver *Event) Daily() schedule.Event { event := receiver.Cron(receiver.spliceIntoPosition(1, "0")) return event.Cron(receiver.spliceIntoPosition(2, "0")) } -//DailyAt Schedule the event to run daily at a given time (10:00, 19:30, etc). +// DailyAt Schedule the event to run daily at a given time (10:00, 19:30, etc). func (receiver *Event) DailyAt(time string) schedule.Event { segments := strings.Split(time, ":") event := receiver.Cron(receiver.spliceIntoPosition(2, segments[0])) @@ -55,75 +55,75 @@ func (receiver *Event) DailyAt(time string) schedule.Event { } } -//DelayIfStillRunning Do not allow the event to overlap each other. +// DelayIfStillRunning Do not allow the event to overlap each other. func (receiver *Event) DelayIfStillRunning() schedule.Event { receiver.delayIfStillRunning = true return receiver } -//EveryMinute Schedule the event to run every minute. +// EveryMinute Schedule the event to run every minute. func (receiver *Event) EveryMinute() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*")) } -//EveryTwoMinutes Schedule the event to run every two minutes. +// EveryTwoMinutes Schedule the event to run every two minutes. func (receiver *Event) EveryTwoMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/2")) } -//EveryThreeMinutes Schedule the event to run every three minutes. +// EveryThreeMinutes Schedule the event to run every three minutes. func (receiver *Event) EveryThreeMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/3")) } -//EveryFourMinutes Schedule the event to run every four minutes. +// EveryFourMinutes Schedule the event to run every four minutes. func (receiver *Event) EveryFourMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/4")) } -//EveryFiveMinutes Schedule the event to run every five minutes. +// EveryFiveMinutes Schedule the event to run every five minutes. func (receiver *Event) EveryFiveMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/5")) } -//EveryTenMinutes Schedule the event to run every ten minutes. +// EveryTenMinutes Schedule the event to run every ten minutes. func (receiver *Event) EveryTenMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/10")) } -//EveryFifteenMinutes Schedule the event to run every fifteen minutes. +// EveryFifteenMinutes Schedule the event to run every fifteen minutes. func (receiver *Event) EveryFifteenMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "*/15")) } -//EveryThirtyMinutes Schedule the event to run every thirty minutes. +// EveryThirtyMinutes Schedule the event to run every thirty minutes. func (receiver *Event) EveryThirtyMinutes() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "0,30")) } -//EveryTwoHours Schedule the event to run every two hours. +// EveryTwoHours Schedule the event to run every two hours. func (receiver *Event) EveryTwoHours() schedule.Event { event := receiver.Cron(receiver.spliceIntoPosition(1, "0")) return event.Cron(receiver.spliceIntoPosition(2, "*/2")) } -//EveryThreeHours Schedule the event to run every three hours. +// EveryThreeHours Schedule the event to run every three hours. func (receiver *Event) EveryThreeHours() schedule.Event { event := receiver.Cron(receiver.spliceIntoPosition(1, "0")) return event.Cron(receiver.spliceIntoPosition(2, "*/3")) } -//EveryFourHours Schedule the event to run every four hours. +// EveryFourHours Schedule the event to run every four hours. func (receiver *Event) EveryFourHours() schedule.Event { event := receiver.Cron(receiver.spliceIntoPosition(1, "0")) return event.Cron(receiver.spliceIntoPosition(2, "*/4")) } -//EverySixHours Schedule the event to run every six hours. +// EverySixHours Schedule the event to run every six hours. func (receiver *Event) EverySixHours() schedule.Event { event := receiver.Cron(receiver.spliceIntoPosition(1, "0")) @@ -158,12 +158,12 @@ func (receiver *Event) GetDelayIfStillRunning() bool { return receiver.delayIfStillRunning } -//Hourly Schedule the event to run hourly. +// Hourly Schedule the event to run hourly. func (receiver *Event) Hourly() schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, "0")) } -//HourlyAt Schedule the event to run hourly at a given offset in the hour. +// HourlyAt Schedule the event to run hourly at a given offset in the hour. func (receiver *Event) HourlyAt(offset []string) schedule.Event { return receiver.Cron(receiver.spliceIntoPosition(1, strings.Join(offset, ","))) } @@ -184,14 +184,14 @@ func (receiver *Event) OnOneServer() schedule.Event { return receiver } -//SkipIfStillRunning Do not allow the event to overlap each other. +// SkipIfStillRunning Do not allow the event to overlap each other. func (receiver *Event) SkipIfStillRunning() schedule.Event { receiver.skipIfStillRunning = true return receiver } -//spliceIntoPosition Splice the given value into the given position of the expression. +// spliceIntoPosition Splice the given value into the given position of the expression. func (receiver *Event) spliceIntoPosition(position int, value string) string { segments := strings.Split(receiver.GetCron(), " ") diff --git a/validation/console/stubs.go b/validation/console/stubs.go index 80b17fe28..9449a8f10 100644 --- a/validation/console/stubs.go +++ b/validation/console/stubs.go @@ -13,17 +13,17 @@ import ( type DummyRule struct { } -//Signature The name of the rule. +// Signature The name of the rule. func (receiver *DummyRule) Signature() string { return "DummyName" } -//Passes Determine if the validation rule passes. +// Passes Determine if the validation rule passes. func (receiver *DummyRule) Passes(data validation.Data, val any, options ...any) bool { return true } -//Message Get the validation error message. +// Message Get the validation error message. func (receiver *DummyRule) Message() string { return "" }