Skip to content

Commit

Permalink
Support jest-environment directive (#46)
Browse files Browse the repository at this point in the history
* Support jest-environment directive

* Fix test case
  • Loading branch information
CalebAlbers committed Feb 27, 2023
1 parent 4af9285 commit 7e4c65c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions addlicense/main.go
Expand Up @@ -295,13 +295,13 @@ func walk(ch chan<- *file, start string, logger *log.Logger) error {
// Patterns are assumed to be valid.
func fileMatches(path string, patterns []string) bool {
for _, p := range patterns {

if runtime.GOOS == "windows" {
// If on windows, change path seperators to /
// in order for patterns to compare correctly
// in order for patterns to compare correctly
path = filepath.ToSlash(path)
}

// ignore error, since we assume patterns are valid
if match, _ := doublestar.Match(p, path); match {
return true
Expand Down Expand Up @@ -412,6 +412,7 @@ var head = []string{
"<?php", // PHP opening tag
"# escape", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
"# syntax", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
"/** @jest-environment", // Jest Environment string https://jestjs.io/docs/configuration#testenvironment-string
}

func hashBang(b []byte) []byte {
Expand Down
1 change: 1 addition & 0 deletions addlicense/main_test.go
Expand Up @@ -245,6 +245,7 @@ func TestAddLicense(t *testing.T) {
{"<?php\ncontent", "<?php\n// HYS\n\ncontent", true},
{"# escape: `\ncontent", "# escape: `\n// HYS\n\ncontent", true},
{"# syntax: docker/dockerfile:1.3\ncontent", "# syntax: docker/dockerfile:1.3\n// HYS\n\ncontent", true},
{"/** @jest-environment jsdom */\ncontent", "/** @jest-environment jsdom */\n// HYS\n\ncontent", true},

// ensure files with existing license or generated files are
// skipped. No need to test all permutations of these, since
Expand Down

0 comments on commit 7e4c65c

Please sign in to comment.