1
1
package main
2
2
3
3
import (
4
- "encoding/json"
5
4
"fmt"
6
5
"os"
7
6
"path/filepath"
@@ -13,8 +12,6 @@ import (
13
12
"github.com/errata-ai/vale/v3/internal/core"
14
13
)
15
14
16
- var library = "https://raw.githubusercontent.com/errata-ai/styles/master/library.json"
17
-
18
15
func initPath (cfg * core.Config ) error {
19
16
// The first entry is always the default `StylesPath`.
20
17
stylesPath := cfg .StylesPath ()
@@ -36,29 +33,13 @@ func initPath(cfg *core.Config) error {
36
33
}
37
34
38
35
func readPkg (pkg , path string , idx int ) error {
39
- lookup , err := getLibrary (path )
40
- if err != nil {
41
- return err
42
- }
43
-
44
- found := false
45
- for _ , entry := range lookup {
46
- if pkg == entry .Name {
47
- found = true
48
- if err = download (pkg , entry .URL , path , idx ); err != nil {
49
- return err
50
- }
36
+ if core .IsPhrase (pkg ) && ! core .IsDir (pkg ) {
37
+ entry := inLibrary (pkg , path )
38
+ if entry != "" {
39
+ return download (pkg , entry , path , idx )
51
40
}
52
41
}
53
-
54
- if ! found {
55
- name := fileNameWithoutExt (pkg )
56
- if err = loadPkg (name , pkg , path , idx ); err != nil {
57
- return err
58
- }
59
- }
60
-
61
- return nil
42
+ return loadPkg (fileNameWithoutExt (pkg ), pkg , path , idx )
62
43
}
63
44
64
45
func loadPkg (name , urlOrPath , styles string , index int ) error {
@@ -96,7 +77,7 @@ func download(name, url, styles string, index int) error {
96
77
97
78
if err = fetch (url , dir ); err != nil {
98
79
if strings .Contains (err .Error (), "unsupported protocol scheme" ) {
99
- err = fmt .Errorf ("'%s' is not a valid URL or the local file doesn't exist" , url )
80
+ err = fmt .Errorf ("'%s' is not a valid URL or the directory doesn't exist" , url )
100
81
}
101
82
return core .NewE100 ("download" , err )
102
83
}
@@ -194,16 +175,3 @@ func moveAsset(name, old, new string) error { //nolint:predeclared
194
175
195
176
return cp .Copy (src , dst )
196
177
}
197
-
198
- func getLibrary (_ string ) ([]Style , error ) {
199
- styles := []Style {}
200
-
201
- resp , err := fetchJSON (library )
202
- if err != nil {
203
- return styles , err
204
- } else if err = json .Unmarshal (resp , & styles ); err != nil {
205
- return styles , err
206
- }
207
-
208
- return styles , err
209
- }
0 commit comments