julianhyde commented on code in PR #3250: URL: https://github.com/apache/calcite/pull/3250#discussion_r1223568634
########## core/src/test/java/org/apache/calcite/sql/test/LintTest.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you 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.apache.calcite.sql.test; + +import org.apache.calcite.util.Puffin; +import org.apache.calcite.util.Source; +import org.apache.calcite.util.Sources; +import org.apache.calcite.util.TestUnsafe; +import org.apache.calcite.util.TestUtil; +import org.apache.calcite.util.Util; + +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; + +/** Various automated checks on the documentation. */ +class LintTest { + @SuppressWarnings("Convert2MethodRef") // JDK 8 requires lambdas + private Puffin.Program<GlobalState> makeProgram() { + return Puffin.builder(GlobalState::new, global -> new FileState(global)) + .add(line -> line.fnr() == 1, + line -> line.globalState().fileCount++) + + // Javadoc does not require '</p>', so we do not allow '</p>' + .add(line -> line.state().inJavadoc() + && line.contains("</p>"), + line -> line.state().message("no '</p>'", line)) + + // No "**/" + .add(line -> line.contains("**/") + && line.state().inJavadoc(), + line -> + line.state().message("no '**/'; use '*/'", + line)) + + // A Javadoc paragraph '<p>' must not be on its own line. + .add(line -> line.matches("^ *\\* <p>"), + line -> + line.state().message("<p> must not be on its own line", + line)) + + // A Javadoc paragraph '<p>' must be preceded by a blank Javadoc + // line. + .add(line -> line.matches("^ *\\*"), + line -> line.state().starLine = line.fnr()) + .add(line -> line.matches("^ *\\* <p>.*") + && line.fnr() - 1 != line.state().starLine, + line -> + line.state().message("<p> must be preceded by blank line", + line)) + + // The first "@param" of a javadoc block must be preceded by a blank + // line. + .add(line -> line.matches("^ */\\*\\*.*"), + line -> line.state().javadocStartLine = line.fnr()) + .add(line -> line.matches(".*\\*/"), + line -> line.state().javadocEndLine = line.fnr()) + .add(line -> line.matches("^ *\\* @.*"), + line -> { + if (line.state().inJavadoc() + && line.state().atLine < line.state().javadocStartLine + && line.fnr() - 1 != line.state().starLine) { + line.state().message( + "First @tag must be preceded by blank line", + line); + } + line.state().atLine = line.fnr(); + }) + .build(); + } + + @Test void testProgramWorks() { + final String code = "class {\n" Review Comment: Good catch. Examples should be as realistic as possible. Fixed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
