浏览代码

Simplify returning a new string slice

This did not work in earlier golang versions.

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
Vadim Markovtsev 5 年之前
父节点
当前提交
43216a28a0

+ 1 - 2
contrib/_plugin_example/churn_analysis.go

@@ -73,13 +73,12 @@ func (churn *ChurnAnalysis) Provides() []string {
 // tick - number of ticks since start for each commit
 // author - author of the commit
 func (churn *ChurnAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		hercules.DependencyFileDiff,
 		hercules.DependencyTreeChanges,
 		hercules.DependencyBlobCache,
 		hercules.DependencyTick,
 		hercules.DependencyAuthor}
-	return arr[:]
 }
 
 // ListConfigurationOptions tells the engine which parameters can be changed through the command

+ 1 - 2
internal/core/forks_test.go

@@ -20,8 +20,7 @@ func (item *testForkPipelineItem) Name() string {
 }
 
 func (item *testForkPipelineItem) Provides() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *testForkPipelineItem) Requires() []string {

+ 3 - 6
internal/core/pipeline_test.go

@@ -41,8 +41,7 @@ func (item *testPipelineItem) Name() string {
 }
 
 func (item *testPipelineItem) Provides() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *testPipelineItem) Requires() []string {
@@ -163,13 +162,11 @@ func (item *dependingTestPipelineItem) Name() string {
 }
 
 func (item *dependingTestPipelineItem) Provides() []string {
-	arr := [...]string{"test2"}
-	return arr[:]
+	return []string{"test2"}
 }
 
 func (item *dependingTestPipelineItem) Requires() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *dependingTestPipelineItem) ListConfigurationOptions() []ConfigurationOption {

+ 6 - 12
internal/core/registry_test.go

@@ -28,8 +28,7 @@ func (item *dummyPipelineItem) Name() string {
 }
 
 func (item *dummyPipelineItem) Provides() []string {
-	arr := [...]string{"dummy"}
-	return arr[:]
+	return []string{"dummy"}
 }
 
 func (item *dummyPipelineItem) Requires() []string {
@@ -37,8 +36,7 @@ func (item *dummyPipelineItem) Requires() []string {
 }
 
 func (item *dummyPipelineItem) Features() []string {
-	arr := [...]string{"power"}
-	return arr[:]
+	return []string{"power"}
 }
 
 func (item *dummyPipelineItem) Configure(facts map[string]interface{}) error {
@@ -78,8 +76,7 @@ func (item *dummyPipelineItem2) Name() string {
 }
 
 func (item *dummyPipelineItem2) Provides() []string {
-	arr := [...]string{"dummy2"}
-	return arr[:]
+	return []string{"dummy2"}
 }
 
 func (item *dummyPipelineItem2) Requires() []string {
@@ -87,8 +84,7 @@ func (item *dummyPipelineItem2) Requires() []string {
 }
 
 func (item *dummyPipelineItem2) Features() []string {
-	arr := [...]string{"other"}
-	return arr[:]
+	return []string{"other"}
 }
 
 func (item *dummyPipelineItem2) Configure(facts map[string]interface{}) error {
@@ -121,8 +117,7 @@ func (item *dummyPipelineItem3) Name() string {
 }
 
 func (item *dummyPipelineItem3) Provides() []string {
-	arr := [...]string{"dummy3"}
-	return arr[:]
+	return []string{"dummy3"}
 }
 
 func (item *dummyPipelineItem3) Requires() []string {
@@ -159,8 +154,7 @@ func (item *dummyPipelineItem4) Name() string {
 }
 
 func (item *dummyPipelineItem4) Provides() []string {
-	arr := [...]string{"dummy4"}
-	return arr[:]
+	return []string{"dummy4"}
 }
 
 func (item *dummyPipelineItem4) Requires() []string {

+ 2 - 4
internal/plumbing/blob_cache.go

@@ -107,16 +107,14 @@ func (blobCache *BlobCache) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (blobCache *BlobCache) Provides() []string {
-	arr := [...]string{DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyBlobCache}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (blobCache *BlobCache) Requires() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/diff.go

@@ -52,16 +52,14 @@ func (diff *FileDiff) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (diff *FileDiff) Provides() []string {
-	arr := [...]string{DependencyFileDiff}
-	return arr[:]
+	return []string{DependencyFileDiff}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (diff *FileDiff) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
internal/plumbing/identity/identity.go

@@ -61,8 +61,7 @@ func (detector *Detector) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (detector *Detector) Provides() []string {
-	arr := [...]string{DependencyAuthor}
-	return arr[:]
+	return []string{DependencyAuthor}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 2 - 4
internal/plumbing/languages.go

@@ -33,16 +33,14 @@ func (langs *LanguagesDetection) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (langs *LanguagesDetection) Provides() []string {
-	arr := [...]string{DependencyLanguages}
-	return arr[:]
+	return []string{DependencyLanguages}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (langs *LanguagesDetection) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/line_stats.go

@@ -43,16 +43,14 @@ func (lsc *LinesStatsCalculator) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (lsc *LinesStatsCalculator) Provides() []string {
-	arr := [...]string{DependencyLineStats}
-	return arr[:]
+	return []string{DependencyLineStats}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (lsc *LinesStatsCalculator) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache, DependencyFileDiff}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache, DependencyFileDiff}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/renames.go

@@ -67,16 +67,14 @@ func (ra *RenameAnalysis) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ra *RenameAnalysis) Provides() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ra *RenameAnalysis) Requires() []string {
-	arr := [...]string{DependencyBlobCache, DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyBlobCache, DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
internal/plumbing/ticks.go

@@ -50,8 +50,7 @@ func (ticks *TicksSinceStart) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ticks *TicksSinceStart) Provides() []string {
-	arr := [...]string{DependencyTick}
-	return arr[:]
+	return []string{DependencyTick}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 1 - 2
internal/plumbing/tree_diff.go

@@ -74,8 +74,7 @@ func (treediff *TreeDiff) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (treediff *TreeDiff) Provides() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 3 - 6
internal/plumbing/uast/diff_refiner.go

@@ -31,22 +31,19 @@ func (ref *FileDiffRefiner) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ref *FileDiffRefiner) Provides() []string {
-	arr := [...]string{plumbing.DependencyFileDiff}
-	return arr[:]
+	return []string{plumbing.DependencyFileDiff}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ref *FileDiffRefiner) Requires() []string {
-	arr := [...]string{plumbing.DependencyFileDiff, DependencyUastChanges}
-	return arr[:]
+	return []string{plumbing.DependencyFileDiff, DependencyUastChanges}
 }
 
 // Features which must be enabled for this PipelineItem to be automatically inserted into the DAG.
 func (ref *FileDiffRefiner) Features() []string {
-	arr := [...]string{FeatureUast}
-	return arr[:]
+	return []string{FeatureUast}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 6 - 12
internal/plumbing/uast/uast.go

@@ -108,22 +108,19 @@ func (exr *Extractor) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (exr *Extractor) Provides() []string {
-	arr := [...]string{DependencyUasts}
-	return arr[:]
+	return []string{DependencyUasts}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (exr *Extractor) Requires() []string {
-	arr := [...]string{items.DependencyTreeChanges, items.DependencyBlobCache}
-	return arr[:]
+	return []string{items.DependencyTreeChanges, items.DependencyBlobCache}
 }
 
 // Features which must be enabled for this PipelineItem to be automatically inserted into the DAG.
 func (exr *Extractor) Features() []string {
-	arr := [...]string{FeatureUast}
-	return arr[:]
+	return []string{FeatureUast}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.
@@ -380,16 +377,14 @@ func (uc *Changes) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (uc *Changes) Provides() []string {
-	arr := [...]string{DependencyUastChanges}
-	return arr[:]
+	return []string{DependencyUastChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (uc *Changes) Requires() []string {
-	arr := [...]string{DependencyUasts, items.DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyUasts, items.DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.
@@ -500,8 +495,7 @@ func (saver *ChangesSaver) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (saver *ChangesSaver) Requires() []string {
-	arr := [...]string{DependencyUastChanges}
-	return arr[:]
+	return []string{DependencyUastChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/burndown.go

@@ -199,10 +199,9 @@ func (analyser *BurndownAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (analyser *BurndownAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		items.DependencyFileDiff, items.DependencyTreeChanges, items.DependencyBlobCache,
 		items.DependencyTick, identity.DependencyAuthor}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/comment_sentiment.go

@@ -81,8 +81,7 @@ func (sent *CommentSentimentAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (sent *CommentSentimentAnalysis) Requires() []string {
-	arr := [...]string{uast_items.DependencyUastChanges, items.DependencyTick}
-	return arr[:]
+	return []string{uast_items.DependencyUastChanges, items.DependencyTick}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 3
leaves/commits.go

@@ -5,7 +5,7 @@ import (
 	"io"
 
 	"github.com/gogo/protobuf/proto"
-	git "gopkg.in/src-d/go-git.v4"
+	"gopkg.in/src-d/go-git.v4"
 	"gopkg.in/src-d/go-git.v4/plumbing"
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
 	"gopkg.in/src-d/hercules.v10/internal/core"
@@ -67,9 +67,8 @@ func (ca *CommitsAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ca *CommitsAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		identity.DependencyAuthor, items.DependencyLanguages, items.DependencyLineStats}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/couples.go

@@ -89,8 +89,7 @@ func (couples *CouplesAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (couples *CouplesAnalysis) Requires() []string {
-	arr := [...]string{identity.DependencyAuthor, items.DependencyTreeChanges}
-	return arr[:]
+	return []string{identity.DependencyAuthor, items.DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/devs.go

@@ -81,10 +81,9 @@ func (devs *DevsAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (devs *DevsAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		identity.DependencyAuthor, items.DependencyTreeChanges, items.DependencyTick,
 		items.DependencyLanguages, items.DependencyLineStats}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/file_history.go

@@ -57,8 +57,7 @@ func (history *FileHistoryAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (history *FileHistoryAnalysis) Requires() []string {
-	arr := [...]string{items.DependencyTreeChanges, items.DependencyLineStats, identity.DependencyAuthor}
-	return arr[:]
+	return []string{items.DependencyTreeChanges, items.DependencyLineStats, identity.DependencyAuthor}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/research/typos.go

@@ -82,9 +82,8 @@ func (tdb *TyposDatasetBuilder) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (tdb *TyposDatasetBuilder) Requires() []string {
-	arr := [...]string{
+	return []string{
 		uast_items.DependencyUastChanges, items.DependencyFileDiff, items.DependencyBlobCache}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.