Skip to content

Commit

Permalink
Respond to reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
achew22 committed Mar 11, 2019
1 parent 02df7bb commit 88669fd
Show file tree
Hide file tree
Showing 45 changed files with 265 additions and 94 deletions.
3 changes: 2 additions & 1 deletion BUILD.bazel
Expand Up @@ -28,7 +28,8 @@ gazelle(
gazelle_binary(
name = "gazelle_sass",
languages = DEFAULT_LANGUAGES + [
"@io_bazel_rules_sass//gazelle:go_default_library",
"@io_bazel_rules_sass//gazelle/sass:go_default_library",
],
tags = ["renovatebot"],
visibility = ["//visibility:private"],
)
23 changes: 0 additions & 23 deletions gazelle/parser/at.go

This file was deleted.

16 changes: 0 additions & 16 deletions gazelle/parser/function.go

This file was deleted.

6 changes: 3 additions & 3 deletions gazelle/BUILD.bazel → gazelle/sass/BUILD.bazel
Expand Up @@ -30,7 +30,7 @@ go_library(
importpath = "github.com/bazelbuild/rules_sass/gazelle",
visibility = ["//visibility:public"],
deps = [
"//gazelle/parser:go_default_library",
"//gazelle/sass/internal/parser:go_default_library",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
Expand All @@ -49,7 +49,7 @@ go_test(
args = ["-gazelle=$(location :gazelle_sass)"],
data = [
":gazelle_sass",
"//gazelle/testdata",
"//gazelle/sass/testdata",
],
embed = [":go_default_library"],
importpath = "github.com/bazelbuild/rules_sass/gazelle",
Expand All @@ -64,6 +64,6 @@ gazelle_binary(
name = "gazelle_sass",
# keep
languages = [
"@io_bazel_rules_sass//gazelle:go_default_library",
"@io_bazel_rules_sass//gazelle/sass:go_default_library",
],
)
2 changes: 1 addition & 1 deletion gazelle/config.go → gazelle/sass/config.go
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gazelle
package sass

import (
"flag"
Expand Down
18 changes: 10 additions & 8 deletions gazelle/fileinfo.go → gazelle/sass/fileinfo.go
Expand Up @@ -13,11 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gazelle
package sass

import (
"fmt"
"log"
"os"
"path/filepath"
"sort"
Expand All @@ -30,22 +29,25 @@ type FileInfo struct {
Path, Name string

Imports []string

Errors []string
}

// sassFileInfo takes a dir and file name and parses the .sass file into
// the constituent components, extracting metadata like the set of
// imports that it has.
func sassFileInfo(dir, name string) FileInfo {
// imports that it has. Returns an error object for all errors, if the error is
// fatal FileInfo will be nil.
func sassFileInfo(dir, name string) (FileInfo, error) {
info := FileInfo{
Path: filepath.Join(dir, name),
Name: name,
}

file, err := os.Open(filepath.Join(dir, name))
if err != nil {
log.Printf("%s: error reading sass file: %v", info.Path, err)
return info
return info, err
}
defer file.Close()

s := parser.New(file)

Expand All @@ -64,7 +66,7 @@ func sassFileInfo(dir, name string) FileInfo {
parseError := func(msg string, args ...interface{}) {
// Prepend the file.Name() so we tell the user which file had the parse error.
args = append([]interface{}{file.Name()}, args...)
fmt.Fprintf(os.Stderr, "%s: "+msg+"\n", args...)
info.Errors = append(info.Errors, fmt.Sprintf("%s: "+msg+"\n", args...))
}

for t := scan(); t.Type() != "EOF"; t = scan() {
Expand Down Expand Up @@ -117,5 +119,5 @@ func sassFileInfo(dir, name string) FileInfo {

sort.Strings(info.Imports)

return info
return info, nil
}
11 changes: 7 additions & 4 deletions gazelle/fileinfo_test.go → gazelle/sass/fileinfo_test.go
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gazelle
package sass

import (
"io/ioutil"
Expand Down Expand Up @@ -77,14 +77,17 @@ func TestFileInfo(t *testing.T) {
t.Fatal(err)
}

got := sassFileInfo(dir, tc.name)
got, err := sassFileInfo(dir, tc.name)
if err != nil {
t.Fatal(err)
}

// Reexpose the fields we care bout for testing.
// Clear the fields we don't care about for testing.
got = FileInfo{
Imports: got.Imports,
}
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("Inequalith.\ngot %#v;\nwant %#v", got, tc.want)
t.Errorf("FileInfo don't match expectations.\ngot %#v;\nwant %#v", got, tc.want)
}
})
}
Expand Down
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gazelle
package sass

import (
"flag"
Expand Down Expand Up @@ -42,9 +42,6 @@ func runGazelle(dir string) error {

err := cmd.Run()

// Flush stdout/stderr since this makes log output show up more often.
os.Stdout.Sync()
os.Stderr.Sync()
return err
}

Expand Down Expand Up @@ -102,8 +99,9 @@ func TestTestdata(t *testing.T) {
}

err := filepath.Walk(testSuitePath, func(path string, info os.FileInfo, err error) error {
// There is no need to process directories. Skip them.
if info.IsDir() {
// There is no need to process directories or if the input path is
// already an error condition. Skip these cases.
if err != nil || info.IsDir() {
return nil
}

Expand All @@ -112,14 +110,19 @@ func TestTestdata(t *testing.T) {
return fmt.Errorf("Unable to read file %q. Err: %v", path, err)
}

// content is a []byte not a string so it has to be typecast and we can't define the filespec at the beginning.
fileSpec := testtools.FileSpec{Path: strings.TrimPrefix(path, testSuitePath), Content: string(content)}
// By contract errors can't happen since we are finding the relative
// path of a file inside the path that we are walking.
relPath, _ := filepath.Rel(testSuitePath, path)

// content is a []byte not a string so it has to be typecast and we
// can't define the filespec at the beginning.
fileSpec := testtools.FileSpec{Path: relPath, Content: string(content)}

if strings.HasSuffix(path, "/BUILD.bazel.in") {
fileSpec.Path = strings.TrimSuffix(strings.TrimPrefix(path, testSuitePath), "BUILD.bazel.in") + "BUILD.bazel"
fileSpec.Path = strings.TrimSuffix(relPath, ".in")
files = append(files, fileSpec)
} else if strings.HasSuffix(path, "/BUILD.bazel.out") {
fileSpec.Path = strings.TrimSuffix(strings.TrimPrefix(path, testSuitePath), "BUILD.bazel.out") + "BUILD.bazel"
fileSpec.Path = strings.TrimSuffix(relPath, ".out")
want = append(want, fileSpec)
} else {
files = append(files, fileSpec)
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions gazelle/sass/internal/parser/at.go
@@ -0,0 +1,37 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
"fmt"
)

// At is an at keyword token.
type At struct {
// The kind of at token.
Ident IdentLike
}

func (a *At) String() string {
return fmt.Sprintf("<At %q>", a.Ident.String())
}
func (a *At) Type() string { return "At" }

var _ Token = &At{}

func (s *Scanner) scanAt() *At {
// Create a buffer and read the current character into it.
return &At{Ident: s.scanIdent()}
}
@@ -1,3 +1,17 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
Expand Down
14 changes: 14 additions & 0 deletions gazelle/parser/digit.go → gazelle/sass/internal/parser/digit.go
@@ -1,3 +1,17 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
Expand Down
30 changes: 30 additions & 0 deletions gazelle/sass/internal/parser/function.go
@@ -0,0 +1,30 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import "fmt"

// Function is a function token.
type Function struct {
// The text inside of the comment.
Value string
}

func (f *Function) String() string {
return fmt.Sprintf("<Function %q>", f.Value)
}
func (_ *Function) Type() string { return "Function" }

var _ Token = &Function{}
14 changes: 14 additions & 0 deletions gazelle/parser/hash.go → gazelle/sass/internal/parser/hash.go
@@ -1,3 +1,17 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
Expand Down
14 changes: 14 additions & 0 deletions gazelle/parser/ident.go → gazelle/sass/internal/parser/ident.go
@@ -1,3 +1,17 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
Expand Down
@@ -1,3 +1,17 @@
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parser

import (
Expand Down

0 comments on commit 88669fd

Please sign in to comment.