Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3c95bd4e
Commit
3c95bd4e
authored
Jul 24, 2015
by
Eric Paris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a whitespace munger
Strips all trailing whitespace from non-preformatted blocks
parent
8886a994
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
91 additions
and
14 deletions
+91
-14
headers.go
cmd/mungedocs/headers.go
+1
-1
headers_test.go
cmd/mungedocs/headers_test.go
+1
-1
kubectl_dash_f.go
cmd/mungedocs/kubectl_dash_f.go
+1
-1
kubectl_dash_f_test.go
cmd/mungedocs/kubectl_dash_f_test.go
+1
-1
links.go
cmd/mungedocs/links.go
+2
-2
links_test.go
cmd/mungedocs/links_test.go
+2
-2
mungedocs.go
cmd/mungedocs/mungedocs.go
+5
-4
preformatted.go
cmd/mungedocs/preformatted.go
+1
-1
preformatted_test.go
cmd/mungedocs/preformatted_test.go
+1
-1
whitespace.go
cmd/mungedocs/whitespace.go
+31
-0
whitespace_test.go
cmd/mungedocs/whitespace_test.go
+45
-0
No files found.
cmd/mungedocs/headers.go
View file @
3c95bd4e
...
@@ -56,7 +56,7 @@ func fixHeaderLine(mlines mungeLines, newlines mungeLines, linenum int) mungeLin
...
@@ -56,7 +56,7 @@ func fixHeaderLine(mlines mungeLines, newlines mungeLines, linenum int) mungeLin
}
}
// Header lines need whitespace around them and after the #s.
// Header lines need whitespace around them and after the #s.
func
check
HeaderLines
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
func
update
HeaderLines
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
out
mungeLines
var
out
mungeLines
for
i
,
mline
:=
range
mlines
{
for
i
,
mline
:=
range
mlines
{
if
mline
.
preformatted
{
if
mline
.
preformatted
{
...
...
cmd/mungedocs/headers_test.go
View file @
3c95bd4e
...
@@ -64,7 +64,7 @@ func TestHeaderLines(t *testing.T) {
...
@@ -64,7 +64,7 @@ func TestHeaderLines(t *testing.T) {
for
i
,
c
:=
range
cases
{
for
i
,
c
:=
range
cases
{
in
:=
getMungeLines
(
c
.
in
)
in
:=
getMungeLines
(
c
.
in
)
expected
:=
getMungeLines
(
c
.
expected
)
expected
:=
getMungeLines
(
c
.
expected
)
actual
,
err
:=
check
HeaderLines
(
"filename.md"
,
in
)
actual
,
err
:=
update
HeaderLines
(
"filename.md"
,
in
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
if
!
actual
.
Equal
(
expected
)
{
if
!
actual
.
Equal
(
expected
)
{
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
...
...
cmd/mungedocs/kubectl_dash_f.go
View file @
3c95bd4e
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
// Looks for lines that have kubectl commands with -f flags and files that
// Looks for lines that have kubectl commands with -f flags and files that
// don't exist.
// don't exist.
func
check
KubectlFileTargets
(
file
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
func
update
KubectlFileTargets
(
file
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
errors
[]
string
var
errors
[]
string
for
i
,
mline
:=
range
mlines
{
for
i
,
mline
:=
range
mlines
{
if
!
mline
.
preformatted
{
if
!
mline
.
preformatted
{
...
...
cmd/mungedocs/kubectl_dash_f_test.go
View file @
3c95bd4e
...
@@ -132,7 +132,7 @@ func TestKubectlDashF(t *testing.T) {
...
@@ -132,7 +132,7 @@ func TestKubectlDashF(t *testing.T) {
for
i
,
c
:=
range
cases
{
for
i
,
c
:=
range
cases
{
repoRoot
=
""
repoRoot
=
""
in
:=
getMungeLines
(
c
.
in
)
in
:=
getMungeLines
(
c
.
in
)
_
,
err
:=
check
KubectlFileTargets
(
"filename.md"
,
in
)
_
,
err
:=
update
KubectlFileTargets
(
"filename.md"
,
in
)
if
err
!=
nil
&&
c
.
ok
{
if
err
!=
nil
&&
c
.
ok
{
t
.
Errorf
(
"case[%d]: expected success, got %v"
,
i
,
err
)
t
.
Errorf
(
"case[%d]: expected success, got %v"
,
i
,
err
)
}
}
...
...
cmd/mungedocs/links.go
View file @
3c95bd4e
...
@@ -115,9 +115,9 @@ func processLink(in string, filePath string) (string, error) {
...
@@ -115,9 +115,9 @@ func processLink(in string, filePath string) (string, error) {
return
out
,
nil
return
out
,
nil
}
}
//
check
Links assumes lines has links in markdown syntax, and verifies that
//
update
Links assumes lines has links in markdown syntax, and verifies that
// any relative links actually point to files that exist.
// any relative links actually point to files that exist.
func
check
Links
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
func
update
Links
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
out
mungeLines
var
out
mungeLines
errors
:=
[]
string
{}
errors
:=
[]
string
{}
...
...
cmd/mungedocs/links_test.go
View file @
3c95bd4e
...
@@ -35,7 +35,7 @@ func TestBadLinks(t *testing.T) {
...
@@ -35,7 +35,7 @@ func TestBadLinks(t *testing.T) {
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
in
:=
getMungeLines
(
c
.
in
)
in
:=
getMungeLines
(
c
.
in
)
_
,
err
:=
check
Links
(
"filename.md"
,
in
)
_
,
err
:=
update
Links
(
"filename.md"
,
in
)
assert
.
Error
(
t
,
err
)
assert
.
Error
(
t
,
err
)
}
}
}
}
...
@@ -67,7 +67,7 @@ func TestGoodLinks(t *testing.T) {
...
@@ -67,7 +67,7 @@ func TestGoodLinks(t *testing.T) {
for
i
,
c
:=
range
cases
{
for
i
,
c
:=
range
cases
{
in
:=
getMungeLines
(
c
.
in
)
in
:=
getMungeLines
(
c
.
in
)
expected
:=
getMungeLines
(
c
.
expected
)
expected
:=
getMungeLines
(
c
.
expected
)
actual
,
err
:=
check
Links
(
"filename.md"
,
in
)
actual
,
err
:=
update
Links
(
"filename.md"
,
in
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
if
!
actual
.
Equal
(
expected
)
{
if
!
actual
.
Equal
(
expected
)
{
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
...
...
cmd/mungedocs/mungedocs.go
View file @
3c95bd4e
...
@@ -46,13 +46,14 @@ Examples:
...
@@ -46,13 +46,14 @@ Examples:
// All of the munge operations to perform.
// All of the munge operations to perform.
// TODO: allow selection from command line. (e.g., just check links in the examples directory.)
// TODO: allow selection from command line. (e.g., just check links in the examples directory.)
allMunges
=
[]
munge
{
allMunges
=
[]
munge
{
{
"remove-whitespace"
,
updateWhitespace
},
{
"table-of-contents"
,
updateTOC
},
{
"table-of-contents"
,
updateTOC
},
{
"unversioned-warning"
,
updateUnversionedWarning
},
{
"unversioned-warning"
,
updateUnversionedWarning
},
{
"
check-links"
,
check
Links
},
{
"
md-links"
,
update
Links
},
{
"blank-lines-surround-preformatted"
,
check
Preformatted
},
{
"blank-lines-surround-preformatted"
,
update
Preformatted
},
{
"header-lines"
,
check
HeaderLines
},
{
"header-lines"
,
update
HeaderLines
},
{
"analytics"
,
updateAnalytics
},
{
"analytics"
,
updateAnalytics
},
{
"kubectl-dash-f"
,
check
KubectlFileTargets
},
{
"kubectl-dash-f"
,
update
KubectlFileTargets
},
{
"sync-examples"
,
syncExamples
},
{
"sync-examples"
,
syncExamples
},
}
}
availableMungeList
=
func
()
string
{
availableMungeList
=
func
()
string
{
...
...
cmd/mungedocs/preformatted.go
View file @
3c95bd4e
...
@@ -18,7 +18,7 @@ package main
...
@@ -18,7 +18,7 @@ package main
// Blocks of ``` need to have blank lines on both sides or they don't look
// Blocks of ``` need to have blank lines on both sides or they don't look
// right in HTML.
// right in HTML.
func
check
Preformatted
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
func
update
Preformatted
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
out
mungeLines
var
out
mungeLines
inpreformat
:=
false
inpreformat
:=
false
for
i
,
mline
:=
range
mlines
{
for
i
,
mline
:=
range
mlines
{
...
...
cmd/mungedocs/preformatted_test.go
View file @
3c95bd4e
...
@@ -48,7 +48,7 @@ func TestPreformatted(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestPreformatted(t *testing.T) {
for
i
,
c
:=
range
cases
{
for
i
,
c
:=
range
cases
{
in
:=
getMungeLines
(
c
.
in
)
in
:=
getMungeLines
(
c
.
in
)
expected
:=
getMungeLines
(
c
.
expected
)
expected
:=
getMungeLines
(
c
.
expected
)
actual
,
err
:=
check
Preformatted
(
"filename.md"
,
in
)
actual
,
err
:=
update
Preformatted
(
"filename.md"
,
in
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
if
!
actual
.
Equal
(
expected
)
{
if
!
actual
.
Equal
(
expected
)
{
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
t
.
Errorf
(
"case[%d]: expected %q got %q"
,
i
,
c
.
expected
,
actual
.
String
())
...
...
cmd/mungedocs/whitespace.go
0 → 100644
View file @
3c95bd4e
/*
Copyright 2015 The Kubernetes 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
main
// Remove all trailing whitespace
func
updateWhitespace
(
file
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
out
mungeLines
for
_
,
mline
:=
range
mlines
{
if
mline
.
preformatted
{
out
=
append
(
out
,
mline
)
continue
}
newline
:=
trimRightSpace
(
mline
.
data
)
out
=
append
(
out
,
newMungeLine
(
newline
))
}
return
out
,
nil
}
cmd/mungedocs/whitespace_test.go
0 → 100644
View file @
3c95bd4e
/*
Copyright 2015 The Kubernetes 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
main
import
(
"testing"
"github.com/stretchr/testify/assert"
)
func
Test_updateWhiteSpace
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
in
string
expected
string
}{
{
""
,
""
},
{
"
\n
"
,
"
\n
"
},
{
"
\t
\t
\n
"
,
"
\n
"
},
{
"bob
\t
"
,
"bob"
},
{
"```
\n
\n
```
\n
"
,
"```
\n
\n
```
\n
"
},
}
for
i
,
c
:=
range
cases
{
in
:=
getMungeLines
(
c
.
in
)
expected
:=
getMungeLines
(
c
.
expected
)
actual
,
err
:=
updateWhitespace
(
"filename.md"
,
in
)
assert
.
NoError
(
t
,
err
)
if
!
expected
.
Equal
(
actual
)
{
t
.
Errorf
(
"Case[%d] Expected Whitespace '%v' but got '%v'"
,
i
,
string
(
expected
.
Bytes
()),
string
(
actual
.
Bytes
()))
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment