Browse Source

updated symbols spacing ruleset

bmallred 9 years ago
parent
commit
2ded7f1f21
2 changed files with 32 additions and 10 deletions
  1. 21 7
      rules/symbolsMustBeSpacedCorrectly.go
  2. 11 3
      rules/symbolsMustBeSpacedCorrectly_test.go

+ 21 - 7
rules/symbolsMustBeSpacedCorrectly.go

35
35
36
		if !(short || long) {
36
		if !(short || long) {
37
			// Look for pairings
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
			// Incrementors and decrementors
43
			// Incrementors and decrementors
42
			re = regexp.MustCompile(`([^\(])([\W])(\+\+|\-\-)(\w)`)
44
			re = regexp.MustCompile(`([^\(])([\W])(\+\+|\-\-)(\w)`)
44
			re = regexp.MustCompile(`(\w)(\+\+|\-\-)([^\)])`)
46
			re = regexp.MustCompile(`(\w)(\+\+|\-\-)([^\)])`)
45
			line = re.ReplaceAll(line, []byte("$1$2 $3$4"))
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
			// Fix generics
67
			// Fix generics
54
			re = regexp.MustCompile(`( < )(.*)( >\s*)`)
68
			re = regexp.MustCompile(`( < )(.*)( >\s*)`)

+ 11 - 3
rules/symbolsMustBeSpacedCorrectly_test.go

26
	if (1+1==2) i-1+(i*3)/(i/1)
26
	if (1+1==2) i-1+(i*3)/(i/1)
27
	a&&!b
27
	a&&!b
28
	if!(true);
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
	expected := []byte(`/// <summary>
34
	expected := []byte(`/// <summary>
31
	int i = 0;
35
	int i = 0;
32
	if (i == 0) i += 2;
36
	if (i == 0) i += 2;
40
	/* <This is a comment>
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
	if (i || i) --i;
48
	if (i || i) --i;
45
	if (i && i) i-- * 0;
49
	if (i && i) i-- * 0;
46
	if (1 + 1 == 2) i - 1 + (i * 3) / (i / 1)
50
	if (1 + 1 == 2) i - 1 + (i * 3) / (i / 1)
47
	a && !b
51
	a && !b
48
	if !(true);
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
	actual := applySymbolsMustBeSpacedCorrectly(input)
59
	actual := applySymbolsMustBeSpacedCorrectly(input)
52
	if !bytes.Equal(expected, actual) {
60
	if !bytes.Equal(expected, actual) {