forked from scalastyle/scalastyle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
924d8af
commit d1d0dcb
Showing
4 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/scala/org/scalastyle/scalariform/XmlLiteralChecker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2011-2012 the original author or authors. | ||
// See the LICENCE.txt file distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// 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 org.scalastyle.scalariform; | ||
|
||
import org.scalastyle.PositionError | ||
import org.scalastyle.ScalariformChecker | ||
import org.scalastyle.ScalastyleError | ||
import VisitorHelper.visit | ||
import scalariform.parser.CompilationUnit | ||
import scalariform.parser.Refinement | ||
import scalariform.parser.XmlExpr | ||
|
||
class XmlLiteralChecker extends ScalariformChecker { | ||
val errorKey = "xml.literal" | ||
|
||
final def verify(ast: CompilationUnit): List[ScalastyleError] = { | ||
VisitorHelper.getAll[XmlExpr](ast.immediateChildren(0)).map(t => PositionError(t.firstToken.offset)) | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/test/scala/org/scalastyle/scalariform/XmlLiteralCheckerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (C) 2011-2012 the original author or authors. | ||
// See the LICENCE.txt file distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// 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 org.scalastyle.scalariform | ||
|
||
import org.scalatest.junit.AssertionsForJUnit | ||
import org.junit.Test | ||
import org.scalastyle.file.CheckerTest | ||
|
||
// scalastyle:off magic.number | ||
|
||
class XmlLiteralCheckerTest extends AssertionsForJUnit with CheckerTest { | ||
|
||
protected val classUnderTest = classOf[XmlLiteralChecker] | ||
|
||
protected val key = "xml.literal" | ||
|
||
@Test def testZeroErrors(): Unit = { | ||
val source = """ | ||
class C1 { | ||
def m1(n: Int) = n | ||
} | ||
"""; | ||
assertErrors(List(), source) | ||
} | ||
|
||
@Test def testOneError(): Unit = { | ||
val source = """ | ||
class C1 { | ||
val f = <foobar/> | ||
} | ||
""" | ||
assertErrors(List(columnError(3, 10)), source) | ||
} | ||
|
||
@Test def testTwoErrors(): Unit = { | ||
val source = """ | ||
class C1 { | ||
val f1 = <foobar/> | ||
val f2 = <foobar/> | ||
} | ||
""" | ||
assertErrors(List(columnError(3, 11), columnError(4, 11)), source) | ||
} | ||
|
||
@Test def testMultiLine(): Unit = { | ||
val source = """ | ||
class C1 { | ||
val f = <foobar> | ||
<foo>></foo> | ||
</foobar> | ||
} | ||
""" | ||
assertErrors(List(columnError(3, 10)), source) | ||
} | ||
} |