浏览代码

updated symbols spacing ruleset

bmallred 9 年之前
父节点
当前提交
2ded7f1f21
共有 2 个文件被更改,包括 32 次插入10 次删除
  1. 21 7
      rules/symbolsMustBeSpacedCorrectly.go
  2. 11 3
      rules/symbolsMustBeSpacedCorrectly_test.go

+ 21 - 7
rules/symbolsMustBeSpacedCorrectly.go

@ -35,8 +35,10 @@ func applySymbolsMustBeSpacedCorrectly(source []byte) []byte {
35 35
36 36
		if !(short || long) {
37 37
			// Look for pairings
38
			re := regexp.MustCompile(`(\w?)([<>!\+\-\*\^%/\^=&\|]?[=\|&]|[<>])(\w?)`)
39
			line = re.ReplaceAll(line, []byte("$1 $2 $3"))
38
			re := regexp.MustCompile(`([\w\)])([<>!\+\-\*\^%/\^=&\|\?]?[=\|&\?]|[<>\?\:])`)
39
			line = re.ReplaceAll(line, []byte("$1 $2"))
40
			re = regexp.MustCompile(`([<>!\+\-\*\^%/\^=&\|\?]?[=\|&\?]|[<>\?\:])([\w!])`)
41
			line = re.ReplaceAll(line, []byte("$1 $2"))
40 42
41 43
			// Incrementors and decrementors
42 44
			re = regexp.MustCompile(`([^\(])([\W])(\+\+|\-\-)(\w)`)
@ -44,11 +46,23 @@ func applySymbolsMustBeSpacedCorrectly(source []byte) []byte {
44 46
			re = regexp.MustCompile(`(\w)(\+\+|\-\-)([^\)])`)
45 47
			line = re.ReplaceAll(line, []byte("$1$2 $3$4"))
46 48
47
			// // Singlets
48
			// re = regexp.MustCompile(`([\+\-\*/][^<>=\-\+\)]?)(\w)`)
49
			// line = re.ReplaceAll(line, []byte("$1 $2"))
50
			// re = regexp.MustCompile(`(\w)([\+\-\*/][^<>=\-\+\)]?)`)
51
			// line = re.ReplaceAll(line, []byte("$1 $2"))
49
			// Unary operators
50
			re = regexp.MustCompile(`([\w])([!])([\w|\(])`)
51
			line = re.ReplaceAll(line, []byte("$1 $2$3"))
52
53
			// Singlets
54
			re = regexp.MustCompile(`([\w\)])([\*/])`)
55
			line = re.ReplaceAll(line, []byte("$1 $2"))
56
			re = regexp.MustCompile(`([\*/])([\w\(])`)
57
			line = re.ReplaceAll(line, []byte("$1 $2"))
58
			re = regexp.MustCompile(`([^\+])([\+])([^\+=])`)
59
			line = re.ReplaceAll(line, []byte("$1 $2 $3"))
60
			re = regexp.MustCompile(`([^\-])([\-])([^\-=])`)
61
			line = re.ReplaceAll(line, []byte("$1 $2 $3"))
62
63
			// Fix negatives
64
			re = regexp.MustCompile(`([\+=<>\?])([ ])([\-])([ ])([\d])`)
65
			line = re.ReplaceAll(line, []byte("$1 $3$5"))
52 66
53 67
			// Fix generics
54 68
			re = regexp.MustCompile(`( < )(.*)( >\s*)`)

+ 11 - 3
rules/symbolsMustBeSpacedCorrectly_test.go

@ -26,7 +26,11 @@ func TestSymbolsMustBeSpacedCorrectly(t *testing.T) {
26 26
	if (1+1==2) i-1+(i*3)/(i/1)
27 27
	a&&!b
28 28
	if!(true);
29
	as IEnumerable<Namespace.ClassName>`)
29
	as IEnumerable<Namespace.ClassName>
30
	null??string.Empty;
31
	(true)?true:false;
32
	if (true
33
		&& false)`)
30 34
	expected := []byte(`/// <summary>
31 35
	int i = 0;
32 36
	if (i == 0) i += 2;
@ -40,13 +44,17 @@ func TestSymbolsMustBeSpacedCorrectly(t *testing.T) {
40 44
	/* <This is a comment>
41 45
	 *
42 46
	 */
43
	for (var i = 1; i > -1; i-- ) {}
47
	for (var i = 1; i > -1; i--) {}
44 48
	if (i || i) --i;
45 49
	if (i && i) i-- * 0;
46 50
	if (1 + 1 == 2) i - 1 + (i * 3) / (i / 1)
47 51
	a && !b
48 52
	if !(true);
49
	as IEnumerable<Namespace.ClassName>`)
53
	as IEnumerable<Namespace.ClassName>
54
	null ?? string.Empty;
55
	(true) ? true : false;
56
	if (true
57
		&& false)`)
50 58
51 59
	actual := applySymbolsMustBeSpacedCorrectly(input)
52 60
	if !bytes.Equal(expected, actual) {