├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appveyor.yml ├── its ├── plugin │ ├── plugins │ │ ├── json-custom-rules-plugin │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── sonar │ │ │ │ │ └── json │ │ │ │ │ ├── MyJSONCustomRulesDefinition.java │ │ │ │ │ ├── MyJSONCustomRulesPlugin.java │ │ │ │ │ └── checks │ │ │ │ │ ├── ForbiddenKeysCheck.java │ │ │ │ │ └── ForbiddenStringCheck.java │ │ │ │ └── resources │ │ │ │ └── org │ │ │ │ └── sonar │ │ │ │ └── l10n │ │ │ │ └── json │ │ │ │ └── rules │ │ │ │ └── custom-json │ │ │ │ ├── forbidden-keys.html │ │ │ │ └── forbidden-string.html │ │ └── pom.xml │ ├── pom.xml │ ├── projects │ │ ├── custom-rules │ │ │ └── src │ │ │ │ ├── forbiddenKeys.json │ │ │ │ └── forbiddenString.json │ │ ├── issues │ │ │ └── src │ │ │ │ ├── dir │ │ │ │ └── file.2.json │ │ │ │ └── file.1.json │ │ └── metrics │ │ │ └── src │ │ │ ├── dir │ │ │ └── file2.json │ │ │ └── file1.json │ └── tests │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── sonar │ │ │ └── json │ │ │ ├── CustomRulesTest.java │ │ │ ├── IssuesTest.java │ │ │ ├── MetricsTest.java │ │ │ └── Tests.java │ │ └── resources │ │ └── org │ │ └── sonar │ │ └── json │ │ └── profiles │ │ ├── empty-profile.xml │ │ ├── file-naming-convention-only-profile.xml │ │ └── json-custom-rules-profile.xml ├── pom.xml └── ruling │ ├── pom.xml │ ├── projects │ └── custom │ │ ├── file-name.ko.json │ │ ├── keyRegularExpression.json │ │ ├── newLineEndOfFile.json │ │ ├── noNewLineEndOfFile.json │ │ ├── parsingError.json │ │ ├── puppet │ │ ├── author │ │ │ ├── custom │ │ │ │ └── metadata.json │ │ │ ├── default-issue │ │ │ │ └── metadata.json │ │ │ ├── default │ │ │ │ └── metadata.json │ │ │ └── not-metadata-json-file │ │ │ │ └── notmetadata.json │ │ ├── dependencies │ │ │ ├── duplicated-dependencies │ │ │ │ └── metadata.json │ │ │ ├── invalid-dependencies │ │ │ │ └── metadata.json │ │ │ ├── no-dependencies │ │ │ │ └── metadata.json │ │ │ ├── not-metadata-json-file │ │ │ │ └── notmetadata.json │ │ │ └── valid-dependencies │ │ │ │ └── metadata.json │ │ ├── deprecated-keys │ │ │ ├── metadata.json │ │ │ └── notmetadata.json │ │ ├── license │ │ │ ├── invalid │ │ │ │ └── metadata.json │ │ │ ├── match-required-value-custom │ │ │ │ └── metadata.json │ │ │ ├── match-required-value │ │ │ │ └── metadata.json │ │ │ ├── no-license │ │ │ │ └── metadata.json │ │ │ ├── not-metadata-json-file │ │ │ │ └── notmetadata.json │ │ │ ├── two-licenses │ │ │ │ └── metadata.json │ │ │ ├── valid-proprietary │ │ │ │ └── metadata.json │ │ │ └── valid-spdx │ │ │ │ └── metadata.json │ │ ├── required-keys │ │ │ ├── empty-file │ │ │ │ └── metadata.json │ │ │ ├── missing-keys │ │ │ │ └── metadata.json │ │ │ ├── no-missing-keys │ │ │ │ └── metadata.json │ │ │ └── not-metadata-json-file │ │ │ │ └── notmetadata.json │ │ └── version │ │ │ ├── metadata.json │ │ │ └── notmetadata.json │ │ ├── sample.json │ │ ├── tabCharacter.json │ │ └── utf8WithBOM.json │ └── tests │ ├── pom.xml │ └── src │ └── test │ ├── expected │ ├── json-S1578.json │ ├── json-S2260.json │ ├── json-bom-utf8-files.json │ ├── json-empty-line-end-of-file.json │ ├── json-puppet-deprecated-keys.json │ ├── json-puppet-duplicated-dependencies.json │ ├── json-puppet-enforce-author-value.json │ ├── json-puppet-enforce-license-value.json │ ├── json-puppet-license.json │ ├── json-puppet-required-keys.json │ ├── json-puppet-version.json │ └── json-tab-character.json │ └── java │ └── org │ └── sonar │ └── json │ └── its │ └── JsonRulingTest.java ├── json-checks-testkit ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── sonar │ └── json │ └── checks │ └── verifier │ ├── CheckVerifier.java │ ├── JSONCheckVerifier.java │ ├── TestIssue.java │ └── package-info.java ├── json-checks ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── sonar │ │ │ └── json │ │ │ └── checks │ │ │ ├── CheckList.java │ │ │ ├── CheckUtils.java │ │ │ ├── GenerateRuleDescriptionsBatch.java │ │ │ ├── RuleDescriptionsGenerator.java │ │ │ ├── Tags.java │ │ │ ├── generic │ │ │ ├── BOMCheck.java │ │ │ ├── FileNameCheck.java │ │ │ ├── KeyRegularExpressionCheck.java │ │ │ ├── MissingNewLineAtEndOfFileCheck.java │ │ │ ├── ParsingErrorCheck.java │ │ │ ├── TabCharacterCheck.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── puppet │ │ │ ├── AbstractPuppetCheck.java │ │ │ ├── PuppetDeprecatedKeysCheck.java │ │ │ ├── PuppetDuplicatedDependenciesCheck.java │ │ │ ├── PuppetEnforceAuthorValueCheck.java │ │ │ ├── PuppetEnforceLicenseValueCheck.java │ │ │ ├── PuppetLicenseCheck.java │ │ │ ├── PuppetRequiredKeysCheck.java │ │ │ ├── PuppetVersionCheck.java │ │ │ └── package-info.java │ └── resources │ │ └── org │ │ └── sonar │ │ └── l10n │ │ └── json │ │ └── rules │ │ └── json │ │ ├── S1578.html │ │ ├── S2260.html │ │ ├── bom-utf8-files.html │ │ ├── empty-line-end-of-file.html │ │ ├── key-regular-expression.html │ │ ├── puppet-deprecated-keys.html │ │ ├── puppet-duplicated-dependencies.html │ │ ├── puppet-enforce-author-value.html │ │ ├── puppet-enforce-license-value.html │ │ ├── puppet-required-keys.html │ │ ├── puppet-version.html │ │ ├── tab-character.html │ │ └── template │ │ └── puppet-license.html │ └── test │ ├── java │ └── org │ │ └── sonar │ │ └── json │ │ └── checks │ │ ├── CheckTestUtils.java │ │ ├── generic │ │ ├── BOMCheckTest.java │ │ ├── FileNameCheckTest.java │ │ ├── KeyRegularExpressionCheckTest.java │ │ ├── MissingNewLineAtEndOfFileCheckTest.java │ │ └── TabCharacterCheckTest.java │ │ └── puppet │ │ ├── PuppetDeprecatedKeysCheckTest.java │ │ ├── PuppetDuplicatedDependenciesCheckTest.java │ │ ├── PuppetEnforceAuthorValueCheckTest.java │ │ ├── PuppetEnforceLicenseValueCheckTest.java │ │ ├── PuppetLicenseCheckTest.java │ │ ├── PuppetRequiredKeysCheckTest.java │ │ └── PuppetVersionCheckTest.java │ └── resources │ └── checks │ ├── file-name.ko.json │ ├── keyRegularExpression.json │ ├── newLineEndOfFile.json │ ├── noNewLineEndOfFile.json │ ├── parsingError.json │ ├── puppet │ ├── author │ │ ├── custom │ │ │ └── metadata.json │ │ ├── default-issue │ │ │ └── metadata.json │ │ ├── default │ │ │ └── metadata.json │ │ └── not-metadata-json-file │ │ │ └── notmetadata.json │ ├── dependencies │ │ ├── duplicated-dependencies │ │ │ └── metadata.json │ │ ├── invalid-dependencies │ │ │ └── metadata.json │ │ ├── no-dependencies │ │ │ └── metadata.json │ │ ├── not-metadata-json-file │ │ │ └── notmetadata.json │ │ └── valid-dependencies │ │ │ └── metadata.json │ ├── deprecated-keys │ │ ├── metadata.json │ │ └── notmetadata.json │ ├── license │ │ ├── invalid │ │ │ └── metadata.json │ │ ├── match-required-value-custom │ │ │ └── metadata.json │ │ ├── match-required-value │ │ │ └── metadata.json │ │ ├── no-license │ │ │ └── metadata.json │ │ ├── not-metadata-json-file │ │ │ └── notmetadata.json │ │ ├── two-licenses │ │ │ └── metadata.json │ │ ├── valid-proprietary │ │ │ └── metadata.json │ │ └── valid-spdx │ │ │ └── metadata.json │ ├── required-keys │ │ ├── empty-file │ │ │ └── metadata.json │ │ ├── missing-keys │ │ │ └── metadata.json │ │ ├── no-missing-keys │ │ │ └── metadata.json │ │ └── not-metadata-json-file │ │ │ └── notmetadata.json │ └── version │ │ ├── metadata.json │ │ └── notmetadata.json │ ├── sample.json │ ├── tab-character.json~ │ ├── tabCharacter.json │ ├── utf16BE.json │ ├── utf16LE.json │ └── utf8WithBOM.json ├── json-frontend ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── sonar │ │ ├── json │ │ ├── package-info.java │ │ ├── parser │ │ │ ├── JSONGrammar.java │ │ │ ├── JSONLexicalGrammar.java │ │ │ ├── JSONNodeBuilder.java │ │ │ ├── JSONParserBuilder.java │ │ │ ├── TreeFactory.java │ │ │ └── package-info.java │ │ ├── tree │ │ │ └── impl │ │ │ │ ├── ArrayTreeImpl.java │ │ │ │ ├── FalseTreeImpl.java │ │ │ │ ├── InternalSyntaxSpacing.java │ │ │ │ ├── InternalSyntaxToken.java │ │ │ │ ├── JSONTree.java │ │ │ │ ├── JsonTreeImpl.java │ │ │ │ ├── KeyTreeImpl.java │ │ │ │ ├── LiteralTreeImpl.java │ │ │ │ ├── NullTreeImpl.java │ │ │ │ ├── NumberTreeImpl.java │ │ │ │ ├── ObjectTreeImpl.java │ │ │ │ ├── PairTreeImpl.java │ │ │ │ ├── SeparatedList.java │ │ │ │ ├── StringTreeImpl.java │ │ │ │ ├── TrueTreeImpl.java │ │ │ │ ├── ValueTreeImpl.java │ │ │ │ └── package-info.java │ │ └── visitors │ │ │ ├── CharsetAwareVisitor.java │ │ │ ├── Issues.java │ │ │ ├── JSONVisitorContext.java │ │ │ ├── SyntaxHighlighterVisitor.java │ │ │ ├── metrics │ │ │ ├── LinesOfCodeVisitor.java │ │ │ ├── MetricsVisitor.java │ │ │ ├── StatementsVisitor.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ └── plugins │ │ └── json │ │ └── api │ │ ├── CustomJSONRulesDefinition.java │ │ ├── JSONCheck.java │ │ ├── package-info.java │ │ ├── tree │ │ ├── ArrayTree.java │ │ ├── JsonTree.java │ │ ├── KeyTree.java │ │ ├── LiteralTree.java │ │ ├── ObjectTree.java │ │ ├── PairTree.java │ │ ├── StringTree.java │ │ ├── SyntaxSpacing.java │ │ ├── SyntaxToken.java │ │ ├── Tree.java │ │ ├── ValueTree.java │ │ └── package-info.java │ │ └── visitors │ │ ├── DoubleDispatchVisitor.java │ │ ├── DoubleDispatchVisitorCheck.java │ │ ├── SubscriptionVisitor.java │ │ ├── SubscriptionVisitorCheck.java │ │ ├── TreeVisitor.java │ │ ├── TreeVisitorContext.java │ │ ├── issue │ │ ├── FileIssue.java │ │ ├── Issue.java │ │ ├── IssueLocation.java │ │ ├── LineIssue.java │ │ ├── PreciseIssue.java │ │ └── package-info.java │ │ └── package-info.java │ └── test │ ├── java │ └── org │ │ └── sonar │ │ ├── json │ │ ├── parser │ │ │ ├── ArrayTreeTest.java │ │ │ ├── BOMTreeTest.java │ │ │ ├── ColonTreeTest.java │ │ │ ├── CommaTreeTest.java │ │ │ ├── CommonJsonTreeTest.java │ │ │ ├── CommonSyntaxTokenTreeTest.java │ │ │ ├── FalseTreeTest.java │ │ │ ├── JsonTreeTest.java │ │ │ ├── KeyTreeTest.java │ │ │ ├── LeftBraceTreeTest.java │ │ │ ├── LeftBracketTreeTest.java │ │ │ ├── NullTreeTest.java │ │ │ ├── NumberTreeTest.java │ │ │ ├── ObjectTreeTest.java │ │ │ ├── PairTreeTest.java │ │ │ ├── RightBraceTreeTest.java │ │ │ ├── RightBracketTreeTest.java │ │ │ ├── SeparatedListTest.java │ │ │ ├── StringTreeTest.java │ │ │ ├── TrueTreeTest.java │ │ │ └── ValueTreeTest.java │ │ └── visitors │ │ │ ├── SyntaxHighlighterVisitorTest.java │ │ │ └── metrics │ │ │ ├── MetricsTest.java │ │ │ └── MetricsVisitorTest.java │ │ └── plugins │ │ └── json │ │ └── api │ │ ├── CustomJSONRulesDefinitionTest.java │ │ └── visitors │ │ ├── IssueLocationTest.java │ │ └── IssueTest.java │ └── resources │ ├── file1.json │ ├── many-pairs.json │ ├── many-values.json │ ├── metrics.json │ └── metricsUtf8WithBom.json ├── pom.xml ├── sonar-json-plugin ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── sonar │ │ └── plugins │ │ └── json │ │ ├── IssueSaver.java │ │ ├── JSONChecks.java │ │ ├── JSONLanguage.java │ │ ├── JSONPlugin.java │ │ ├── JSONProfile.java │ │ ├── JSONRulesDefinition.java │ │ ├── JSONSquidSensor.java │ │ └── package-info.java │ └── test │ ├── java │ └── org │ │ └── sonar │ │ └── plugins │ │ └── json │ │ ├── JSONLanguageTest.java │ │ ├── JSONPluginTest.java │ │ ├── JSONProfileTest.java │ │ ├── JSONRulesDefinitionTest.java │ │ └── JSONSquidSensorTest.java │ └── resources │ ├── parsingError.json │ ├── sample.json │ └── sampleUTF8WithBOM.json └── travis.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | 4 | # IntelliJ IDEA 5 | *.iws 6 | *.iml 7 | *.ipr 8 | .idea/ 9 | 10 | # Eclipse 11 | .classpath 12 | .project 13 | .settings 14 | 15 | # ---- Mac OS X 16 | .DS_Store 17 | Icon? 18 | # Thumbnails 19 | ._* 20 | # Files that might appear on external disk 21 | .Spotlight-V100 22 | .Trashes 23 | 24 | # ---- Windows 25 | # Windows image file caches 26 | Thumbs.db 27 | # Folder config file 28 | Desktop.ini 29 | 30 | log.txt 31 | *~ 32 | *.versionsBackup 33 | .sonar 34 | .sonarlint 35 | .scannerwork 36 | sonarlint.json 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | env: 7 | global: 8 | - secure: "brus2c9y+SSEtqSZUXxluckjHb0WJokhtJhjXiF85azEfIx3Rdmwl2bbA4X1gLsDlR594ZjnxAOYMfjQcYesl5AqnNil4lDmJBPiwAXnAXm4DkMbN5VIfFnea93d+pyZFmjTY6YK9slJCzfnQDS/4Tr9EXoRKv+a9ve+Hk9S505ln4iDn2nxYuRJYtEFFLeBTO7aHJFmUpxJZcoAPM6ZLnpH2YAgVg0daFugBT2iPvnPVktPS8vm+JG0aO9T9SHfDNGpOgZPQ00jYpHAx8kCEnia6MdpGFI+llx1whvQqoOa2PxU/YyZu+PsbRy4pA1apvdmS7MrWGNKSUZqwnPLFiA8wNWRPsTBTFTjP1zpt20Cxq71C4dK2rPGdWAOr/Yee3D5fnrru8vHZ9zc6GTOg2KdGs15OvWtqPXix+hryg9drgatIEUZStkkv6rqTPsCk3vgUV9zvJOL0qrCQPkZ7ooDL5ilM7ewwLgnMbhJZ9to1xXXn8lCPpvPkEWykLTyNZbseyMoyp4al/OEDJp/GMSrPJjIgYiJdiNwZxRH2HqZLlv3kOUW571Op7vyx4FRDFY4MX54MinGSyT+bWVwH9mEhfbmuhXaft+2CxDr8QB5lhe6F1C0i/Zm3XNzbzUbUq+PwSX6i05KVr1Un5xFH+GLO8n5+SJ9XxgoClVZpJc=" 9 | - secure: "rm5DovbmGbkGkbF2/lLdTJsEqiK5XYvRNnGHaWlvsedVZXzHvPCPfj5nR5rWCWPD9fBGY51iPr2O00OuCAQowPlKn0eDdF3KGlDIr08FiWQWwZuT+LMh2rsTYVySEeBRyFZe7UqPzpepOQwiBQZpljVzURtVkE6WMVWeAPKNFstXWJAS6afJO1CVGqzTPhRYYDjR/l6VIhdRsGXxeMrk3OAH1g000RKxG7C4LaL3nZugD1M2owOQ/MAnrheCJi1uWChA6yhnMzVrd93C2a7wTTZ9tNf24176CFDz0v3XQcOIet6rpMfJK8Rh/nfEbDFb+PM9thS195yfhGTK4oWrwdpIe/vAKgQkhZc1HDfbEjV/g44vjDnxEF5WclJrQqXZqG0AaEJYQtC89MW50WXjGjq1mi4Ej80/5wcIhiRNO4ohYFhEqw/0mmqRw5Kbc/wGGWS5TMjKaZ3G+Gbr4dT3GfCyzWfi81lFfDb0CLahQseP2CJKqNJDpi4WKjjlqGCaAOfecomwOk536IVIDu7C7P3oRrpNPb2dRaFlxTIEOR5Wim8oCOJTiGu2ruCoaM3cpDoDzb8pl13qfns02EBWVi9DjhtaMzJKZG1uTIdLKYTCT2MlZalJo5Lkk8zoStxfFXUhwHBdUkSBlGeGZt1W7GYHCB9uCrzsdkjkFoGT7UQ=" 10 | matrix: 11 | - SQ_VERSION=LTS 12 | - SQ_VERSION=LATEST_RELEASE 13 | 14 | cache: 15 | directories: 16 | - '$HOME/.m2/repository' 17 | 18 | script: ./travis.sh 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Raising a Bug 2 | While raising a bug, please provide: 3 | * Version of the SonarQube platform 4 | * Version of the JSON plugin 5 | * Log file of the analysis 6 | * Source code to reproduce the error 7 | 8 | ## Contributing 9 | Any contribution is more than welcome! 10 | 11 | You feel like: 12 | * Adding a new check? Just [open an issue](https://github.com/racodond/sonar-css-json/issues/new) to discuss the value of your check. Once validated, code, don't forget to add a lot of unit tests and open a PR. 13 | * Fixing some bugs or improving existing checks? Just open a PR. 14 | 15 | ## Building / Testing / Releasing 16 | * Building and running unit tests: `mvn clean install` 17 | * Building and running unit tests and running integration tests: `mvn clean install -Pits -Dsonar.runtimeVersion=$VERSION` ($VERSION = 'LTS' or 'LATEST_RELEASE'). Behind a proxy, add `-Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128`. 18 | * Releasing on Maven Central: `mvn clean deploy -Possrh` 19 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | cache: 4 | - C:\Users\appveyor\.m2 5 | 6 | install: 7 | - SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0 8 | - SET PATH=C:\maven\apache-maven-3.3.9\bin;%JAVA_HOME%\bin;%PATH% 9 | 10 | - appveyor DownloadFile http://www.us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip 11 | - 7z x apache-maven-3.3.9-bin.zip -oC:\maven 12 | 13 | environment: 14 | matrix: 15 | - SQ_VERSION: "LTS" 16 | - SQ_VERSION: "LATEST_RELEASE" 17 | 18 | platform: 19 | - x64 20 | 21 | build_script: 22 | - mvn clean install -B -DskipTests=true -Dmaven.javadoc.skip=true 23 | 24 | test_script: 25 | - mvn clean install -B -Djna.nosys=true -Pits -Dsonar.runtimeVersion=%SQ_VERSION% 26 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its-plugin-plugins 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-custom-rules-plugin 13 | sonar-plugin 14 | 15 | SonarQube JSON Analyzer :: Integration Tests :: Plugin :: Plugins :: Custom Rules 16 | 17 | 18 | 19 | org.sonarsource.sonarqube 20 | sonar-plugin-api 21 | provided 22 | 23 | 24 | org.codehaus.sonar-plugins.json 25 | sonar-json-plugin 26 | sonar-plugin 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.sonarsource.sonar-packaging-maven-plugin 34 | sonar-packaging-maven-plugin 35 | 1.18.0.372 36 | true 37 | 38 | org.sonar.json.MyJSONCustomRulesPlugin 39 | JSON 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 3.7.0 46 | 47 | 1.8 48 | 1.8 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/src/main/java/org/sonar/json/MyJSONCustomRulesDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json; 21 | 22 | import org.sonar.json.checks.ForbiddenKeysCheck; 23 | import org.sonar.json.checks.ForbiddenStringCheck; 24 | import org.sonar.plugins.json.api.CustomJSONRulesDefinition; 25 | 26 | /** 27 | * Extension point to define a JSON rule repository. 28 | */ 29 | public class MyJSONCustomRulesDefinition extends CustomJSONRulesDefinition { 30 | 31 | /** 32 | * Provide the repository name. 33 | */ 34 | @Override 35 | public String repositoryName() { 36 | return "My JSON Custom Repository"; 37 | } 38 | 39 | /** 40 | * Provide the repository key. 41 | */ 42 | @Override 43 | public String repositoryKey() { 44 | return "custom-json"; 45 | } 46 | 47 | /** 48 | * Provide the list of classes implementing rules. 49 | */ 50 | @Override 51 | public Class[] checkClasses() { 52 | return new Class[] { 53 | ForbiddenKeysCheck.class, 54 | ForbiddenStringCheck.class 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/src/main/java/org/sonar/json/MyJSONCustomRulesPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json; 21 | 22 | import com.google.common.collect.ImmutableList; 23 | import org.sonar.api.Plugin; 24 | 25 | /** 26 | * Extension point to define a SonarQube plugin. 27 | */ 28 | public class MyJSONCustomRulesPlugin implements Plugin { 29 | 30 | @Override 31 | public void define(Context context) { 32 | context.addExtensions( 33 | ImmutableList.of( 34 | MyJSONCustomRulesDefinition.class)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/src/main/java/org/sonar/json/checks/ForbiddenKeysCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | import com.google.common.collect.ImmutableSet; 23 | 24 | import java.util.Set; 25 | 26 | import org.sonar.check.Priority; 27 | import org.sonar.check.Rule; 28 | import org.sonar.plugins.json.api.tree.KeyTree; 29 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitorCheck; 30 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation; 31 | 32 | @Rule( 33 | key = "forbidden-keys", 34 | priority = Priority.MAJOR, 35 | name = "Forbidden keys should not be used", 36 | tags = {"bug"}) 37 | @SqaleConstantRemediation("5min") 38 | public class ForbiddenKeysCheck extends DoubleDispatchVisitorCheck { 39 | 40 | private static final Set FORBIDDEN_KEYS = ImmutableSet.of("foo", "bar"); 41 | 42 | @Override 43 | public void visitKey(KeyTree tree) { 44 | if (FORBIDDEN_KEYS.contains(tree.actualText().toLowerCase())) { 45 | addPreciseIssue(tree, "Remove the usage of this forbidden \"" + tree.actualText() + "\" key."); 46 | } 47 | // super method must be called in order to visit what is under the key node in the syntax tree 48 | super.visitKey(tree); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/src/main/resources/org/sonar/l10n/json/rules/custom-json/forbidden-keys.html: -------------------------------------------------------------------------------- 1 |

2 | The following keys should not be used: 3 |

4 | 8 | -------------------------------------------------------------------------------- /its/plugin/plugins/json-custom-rules-plugin/src/main/resources/org/sonar/l10n/json/rules/custom-json/forbidden-string.html: -------------------------------------------------------------------------------- 1 |

2 | "WTF" should not appear in keys or values. 3 |

4 | -------------------------------------------------------------------------------- /its/plugin/plugins/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its-plugin 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its-plugin-plugins 13 | SonarQube JSON Analyzer :: Integration Tests :: Plugin :: Plugins 14 | pom 15 | 16 | 17 | json-custom-rules-plugin 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /its/plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its-plugin 13 | SonarQube JSON Analyzer :: Integration Tests :: Plugin 14 | pom 15 | 16 | 17 | plugins 18 | tests 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /its/plugin/projects/custom-rules/src/forbiddenKeys.json: -------------------------------------------------------------------------------- 1 | { 2 | "abc": { 3 | "bar": 2 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /its/plugin/projects/custom-rules/src/forbiddenString.json: -------------------------------------------------------------------------------- 1 | { 2 | "abc": { 3 | "abc": "wtf!!" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /its/plugin/projects/issues/src/dir/file.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/plugin/projects/issues/src/file.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/plugin/projects/metrics/src/dir/file2.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}, 7 | "zyy": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 8 | } 9 | 10 | -------------------------------------------------------------------------------- /its/plugin/projects/metrics/src/file1.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/plugin/tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its-plugin 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its-plugin-tests 13 | SonarQube JSON Analyzer :: Integration Tests :: Plugin :: Tests 14 | 15 | 16 | 17 | org.sonarsource.sonarqube 18 | sonar-plugin-api 19 | provided 20 | 21 | 22 | org.sonarsource.orchestrator 23 | sonar-orchestrator 24 | test 25 | 26 | 27 | org.sonarsource.sonarqube 28 | sonar-ws 29 | 6.7 30 | test 31 | 32 | 33 | org.easytesting 34 | fest-assert 35 | test 36 | 37 | 38 | junit 39 | junit 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-surefire-plugin 50 | 51 | 52 | org/sonar/json/Tests.java 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /its/plugin/tests/src/test/resources/org/sonar/json/profiles/empty-profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | empty-profile 4 | json 5 | 6 | 7 | -------------------------------------------------------------------------------- /its/plugin/tests/src/test/resources/org/sonar/json/profiles/file-naming-convention-only-profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | file-naming-convention-only-profile 4 | json 5 | 6 | 7 | json 8 | S1578 9 | MINOR 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /its/plugin/tests/src/test/resources/org/sonar/json/profiles/json-custom-rules-profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | json-custom-rules-profile 4 | json 5 | 6 | 7 | custom-json 8 | forbidden-keys 9 | MAJOR 10 | 11 | 12 | 13 | custom-json 14 | forbidden-string 15 | CRITICAL 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /its/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its 13 | SonarQube JSON Analyzer :: Integration Tests 14 | pom 15 | 16 | Integration tests of the SonarQube JSON analyzer 17 | 2015 18 | 19 | David RACODON 20 | mailto:david.racodon@gmail.com 21 | 22 | 23 | 24 | GNU LGPL 3 25 | http://www.gnu.org/licenses/lgpl.txt 26 | repo 27 | 28 | 29 | 30 | 31 | 32 | racodond 33 | David RACODON 34 | david.racodon@gmail.com 35 | https://www.linkedin.com/pub/david-racodon/11/62/283 36 | 37 | 38 | 39 | 40 | plugin 41 | ruling 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /its/ruling/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its-ruling 13 | SonarQube JSON Analyzer :: Integration Tests :: Ruling 14 | pom 15 | 16 | 17 | tests 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/file-name.ko.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/keyRegularExpression.json: -------------------------------------------------------------------------------- 1 | { 2 | "mykey": {}, 3 | "abc" : [123, 234], 4 | "blabla_mykey_blabla" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "mykey": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/newLineEndOfFile.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/noNewLineEndOfFile.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/parsingError.json: -------------------------------------------------------------------------------- 1 | blabla... -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/author/custom/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/author/default-issue/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "author": [ 6 | "abc", 7 | "def" 8 | ], 9 | "license": "Apache-2.0", 10 | "summary": "A module for a thing", 11 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 14 | "tags": ["things", "stuff"], 15 | "operatingsystem_support": [ 16 | { 17 | "operatingsystem":"RedHat", 18 | "operatingsystemrelease":[ "5.0", "6.0" ] 19 | }, 20 | { 21 | "operatingsystem": "Ubuntu", 22 | "operatingsystemrelease": [ "12.04", "10.04" ] 23 | } 24 | ], 25 | "dependencies": [ 26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 28 | ] 29 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/author/default/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "John Doe", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/author/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "John Doe", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/dependencies/duplicated-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }, 24 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 25 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }, 26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 27 | ] 28 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/dependencies/invalid-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": "abc" 22 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/dependencies/no-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/dependencies/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": "abc" 22 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/dependencies/valid-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/deprecated-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "description": "A module for a thing", 5 | "types": "blabla", 6 | "checksums": "blabla", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/deprecated-keys/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "description": "A module for a thing", 5 | "types": "blabla", 6 | "checksums": "blabla", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/invalid/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/match-required-value-custom/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/match-required-value/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "license": [ "blabla" ], 7 | "summary": "A module for a thing", 8 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 11 | "tags": ["things", "stuff"], 12 | "operatingsystem_support": [ 13 | { 14 | "operatingsystem":"RedHat", 15 | "operatingsystemrelease":[ "5.0", "6.0" ] 16 | }, 17 | { 18 | "operatingsystem": "Ubuntu", 19 | "operatingsystemrelease": [ "12.04", "10.04" ] 20 | } 21 | ], 22 | "dependencies": [ 23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 25 | ] 26 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/no-license/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "summary": "A module for a thing", 6 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 7 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 8 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 9 | "tags": ["things", "stuff"], 10 | "operatingsystem_support": [ 11 | { 12 | "operatingsystem":"RedHat", 13 | "operatingsystemrelease":[ "5.0", "6.0" ] 14 | }, 15 | { 16 | "operatingsystem": "Ubuntu", 17 | "operatingsystemrelease": [ "12.04", "10.04" ] 18 | } 19 | ], 20 | "dependencies": [ 21 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 22 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 23 | ] 24 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/two-licenses/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "license": "Apache-2.0", 7 | "summary": "A module for a thing", 8 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 11 | "tags": ["things", "stuff"], 12 | "operatingsystem_support": [ 13 | { 14 | "operatingsystem":"RedHat", 15 | "operatingsystemrelease":[ "5.0", "6.0" ] 16 | }, 17 | { 18 | "operatingsystem": "Ubuntu", 19 | "operatingsystemrelease": [ "12.04", "10.04" ] 20 | } 21 | ], 22 | "dependencies": [ 23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 25 | ] 26 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/valid-proprietary/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "proprietary", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/license/valid-spdx/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "LGPL-3.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/required-keys/empty-file/metadata.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/its/ruling/projects/custom/puppet/required-keys/empty-file/metadata.json -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/required-keys/missing-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "summary": "A module for a thing", 5 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 8 | "tags": ["things", "stuff"], 9 | "operatingsystem_support": [ 10 | { 11 | "operatingsystem":"RedHat", 12 | "operatingsystemrelease":[ "5.0", "6.0" ] 13 | }, 14 | { 15 | "operatingsystem": "Ubuntu", 16 | "operatingsystemrelease": [ "12.04", "10.04" ] 17 | } 18 | ], 19 | "dependencies": [ 20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 22 | ] 23 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/required-keys/no-missing-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/required-keys/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "summary": "A module for a thing", 5 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 8 | "tags": ["things", "stuff"], 9 | "operatingsystem_support": [ 10 | { 11 | "operatingsystem":"RedHat", 12 | "operatingsystemrelease":[ "5.0", "6.0" ] 13 | }, 14 | { 15 | "operatingsystem": "Ubuntu", 16 | "operatingsystemrelease": [ "12.04", "10.04" ] 17 | } 18 | ], 19 | "dependencies": [ 20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 22 | ] 23 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/version/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "version": "0.1", 5 | "version": "1.0.1-beta", 6 | "version": "abc", 7 | "version": [ "0.1" ], 8 | "author": "Pat", 9 | "license": "Apache-2.0", 10 | "summary": "A module for a thing", 11 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 14 | "tags": ["things", "stuff"], 15 | "operatingsystem_support": [ 16 | { 17 | "operatingsystem":"RedHat", 18 | "operatingsystemrelease":[ "5.0", "6.0" ] 19 | }, 20 | { 21 | "operatingsystem": "Ubuntu", 22 | "operatingsystemrelease": [ "12.04", "10.04" ] 23 | } 24 | ], 25 | "dependencies": [ 26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 28 | ] 29 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/puppet/version/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "version": "0.1", 5 | "version": "1.0.1-beta", 6 | "version": "abc", 7 | "author": "Pat", 8 | "license": "Apache-2.0", 9 | "summary": "A module for a thing", 10 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 11 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 12 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 13 | "tags": ["things", "stuff"], 14 | "operatingsystem_support": [ 15 | { 16 | "operatingsystem":"RedHat", 17 | "operatingsystemrelease":[ "5.0", "6.0" ] 18 | }, 19 | { 20 | "operatingsystem": "Ubuntu", 21 | "operatingsystemrelease": [ "12.04", "10.04" ] 22 | } 23 | ], 24 | "dependencies": [ 25 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 27 | ] 28 | } -------------------------------------------------------------------------------- /its/ruling/projects/custom/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "foo" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "abc": "\"wtf", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/tabCharacter.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [true, null], 4 | "abc" : false, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/ruling/projects/custom/utf8WithBOM.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /its/ruling/tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.codehaus.sonar-plugins.json 8 | json-its-ruling 9 | 2.4-SNAPSHOT 10 | 11 | 12 | json-its-ruling-tests 13 | SonarQube JSON Analyzer :: Integration Tests :: Ruling :: Tests 14 | 15 | 16 | 17 | org.sonarsource.orchestrator 18 | sonar-orchestrator 19 | 20 | 21 | org.sonarsource.analyzer-commons 22 | sonar-analyzer-commons 23 | 24 | 25 | com.google.guava 26 | guava 27 | 28 | 29 | junit 30 | junit 31 | 32 | 33 | org.easytesting 34 | fest-assert 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-surefire-plugin 44 | 45 | 46 | org/sonar/json/its/JsonRulingTest.java 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-S1578.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/file-name.ko.json':[ 3 | 0, 4 | ], 5 | } 6 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-S2260.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/parsingError.json':[ 3 | 1, 4 | ], 5 | } 6 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-bom-utf8-files.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/utf8WithBOM.json':[ 3 | 0, 4 | ], 5 | } 6 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-deprecated-keys.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/deprecated-keys/metadata.json':[ 3 | 4, 4 | 5, 5 | 6, 6 | ], 7 | } 8 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-duplicated-dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/dependencies/duplicated-dependencies/metadata.json':[ 3 | 22, 4 | 23, 5 | ], 6 | 'project:custom/puppet/dependencies/invalid-dependencies/metadata.json':[ 7 | 21, 8 | ], 9 | } 10 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-enforce-author-value.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/author/custom/metadata.json':[ 3 | 4, 4 | ], 5 | 'project:custom/puppet/author/default-issue/metadata.json':[ 6 | 4, 7 | 5, 8 | ], 9 | 'project:custom/puppet/dependencies/duplicated-dependencies/metadata.json':[ 10 | 4, 11 | ], 12 | 'project:custom/puppet/dependencies/invalid-dependencies/metadata.json':[ 13 | 4, 14 | ], 15 | 'project:custom/puppet/dependencies/no-dependencies/metadata.json':[ 16 | 4, 17 | ], 18 | 'project:custom/puppet/dependencies/valid-dependencies/metadata.json':[ 19 | 4, 20 | ], 21 | 'project:custom/puppet/license/invalid/metadata.json':[ 22 | 4, 23 | ], 24 | 'project:custom/puppet/license/match-required-value-custom/metadata.json':[ 25 | 4, 26 | ], 27 | 'project:custom/puppet/license/match-required-value/metadata.json':[ 28 | 4, 29 | ], 30 | 'project:custom/puppet/license/no-license/metadata.json':[ 31 | 4, 32 | ], 33 | 'project:custom/puppet/license/two-licenses/metadata.json':[ 34 | 4, 35 | ], 36 | 'project:custom/puppet/license/valid-proprietary/metadata.json':[ 37 | 4, 38 | ], 39 | 'project:custom/puppet/license/valid-spdx/metadata.json':[ 40 | 4, 41 | ], 42 | 'project:custom/puppet/required-keys/no-missing-keys/metadata.json':[ 43 | 4, 44 | ], 45 | 'project:custom/puppet/version/metadata.json':[ 46 | 8, 47 | ], 48 | } 49 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-enforce-license-value.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/author/custom/metadata.json':[ 3 | 5, 4 | ], 5 | 'project:custom/puppet/author/default-issue/metadata.json':[ 6 | 9, 7 | ], 8 | 'project:custom/puppet/author/default/metadata.json':[ 9 | 5, 10 | ], 11 | 'project:custom/puppet/dependencies/duplicated-dependencies/metadata.json':[ 12 | 5, 13 | ], 14 | 'project:custom/puppet/dependencies/invalid-dependencies/metadata.json':[ 15 | 5, 16 | ], 17 | 'project:custom/puppet/dependencies/no-dependencies/metadata.json':[ 18 | 5, 19 | ], 20 | 'project:custom/puppet/dependencies/valid-dependencies/metadata.json':[ 21 | 5, 22 | ], 23 | 'project:custom/puppet/license/invalid/metadata.json':[ 24 | 5, 25 | ], 26 | 'project:custom/puppet/license/match-required-value-custom/metadata.json':[ 27 | 5, 28 | ], 29 | 'project:custom/puppet/license/match-required-value/metadata.json':[ 30 | 5, 31 | 6, 32 | ], 33 | 'project:custom/puppet/license/two-licenses/metadata.json':[ 34 | 5, 35 | 6, 36 | ], 37 | 'project:custom/puppet/license/valid-proprietary/metadata.json':[ 38 | 5, 39 | ], 40 | 'project:custom/puppet/required-keys/no-missing-keys/metadata.json':[ 41 | 5, 42 | ], 43 | 'project:custom/puppet/version/metadata.json':[ 44 | 9, 45 | ], 46 | } 47 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-license.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/license/invalid/metadata.json':[ 3 | 5, 4 | ], 5 | 'project:custom/puppet/license/match-required-value-custom/metadata.json':[ 6 | 5, 7 | ], 8 | 'project:custom/puppet/license/match-required-value/metadata.json':[ 9 | 5, 10 | 6, 11 | ], 12 | } 13 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-required-keys.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/dependencies/no-dependencies/metadata.json':[ 3 | 0, 4 | ], 5 | 'project:custom/puppet/deprecated-keys/metadata.json':[ 6 | 0, 7 | ], 8 | 'project:custom/puppet/license/no-license/metadata.json':[ 9 | 0, 10 | ], 11 | 'project:custom/puppet/required-keys/empty-file/metadata.json':[ 12 | 0, 13 | ], 14 | 'project:custom/puppet/required-keys/missing-keys/metadata.json':[ 15 | 0, 16 | ], 17 | } 18 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-puppet-version.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/puppet/version/metadata.json':[ 3 | 4, 4 | 5, 5 | 6, 6 | 7, 7 | ], 8 | } 9 | -------------------------------------------------------------------------------- /its/ruling/tests/src/test/expected/json-tab-character.json: -------------------------------------------------------------------------------- 1 | { 2 | 'project:custom/tabCharacter.json':[ 3 | 0, 4 | ], 5 | } 6 | -------------------------------------------------------------------------------- /json-checks-testkit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | org.codehaus.sonar-plugins.json 7 | json 8 | 2.4-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | json-checks-testkit 13 | SonarQube JSON Analyzer :: Check Test Toolkit 14 | 15 | 16 | 17 | ${project.groupId} 18 | json-frontend 19 | 20 | 21 | org.sonarsource.sonarqube 22 | sonar-plugin-api 23 | 24 | 25 | org.sonarsource.sslr-squid-bridge 26 | sslr-squid-bridge 27 | 28 | 29 | junit 30 | junit 31 | 32 | 33 | org.easytesting 34 | fest-assert 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.jacoco 42 | jacoco-maven-plugin 43 | 44 | ${sonar.jacoco.reportPath} 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /json-checks-testkit/src/main/java/org/sonar/json/checks/verifier/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | /** 21 | * Provides helper classes for coding rules implementation 22 | */ 23 | @javax.annotation.ParametersAreNonnullByDefault 24 | package org.sonar.json.checks.verifier; 25 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/CheckList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | import com.google.common.collect.ImmutableList; 23 | 24 | import java.util.Collection; 25 | 26 | import org.sonar.json.checks.generic.*; 27 | import org.sonar.json.checks.puppet.*; 28 | 29 | public final class CheckList { 30 | 31 | public static final String REPOSITORY_KEY = "json"; 32 | public static final String REPOSITORY_NAME = "SonarQube"; 33 | 34 | private CheckList() { 35 | } 36 | 37 | @SuppressWarnings("rawtypes") 38 | public static Collection getChecks() { 39 | return ImmutableList.of( 40 | BOMCheck.class, 41 | FileNameCheck.class, 42 | KeyRegularExpressionCheck.class, 43 | MissingNewLineAtEndOfFileCheck.class, 44 | ParsingErrorCheck.class, 45 | PuppetDeprecatedKeysCheck.class, 46 | PuppetDuplicatedDependenciesCheck.class, 47 | PuppetEnforceAuthorValueCheck.class, 48 | PuppetEnforceLicenseValueCheck.class, 49 | PuppetLicenseCheck.class, 50 | PuppetRequiredKeysCheck.class, 51 | PuppetVersionCheck.class, 52 | TabCharacterCheck.class); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/CheckUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | import org.sonar.check.Rule; 23 | import org.sonar.plugins.json.api.JSONCheck; 24 | 25 | public class CheckUtils { 26 | 27 | public static final String LINK_TO_JAVA_REGEX_PATTERN_DOC = "http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html"; 28 | 29 | private CheckUtils() { 30 | } 31 | 32 | public static String paramsErrorMessage(Class clazz, String message) { 33 | return "Check json:" + clazz.getAnnotation(Rule.class).key() 34 | + " (" + clazz.getAnnotation(Rule.class).name() + "): " 35 | + message; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/GenerateRuleDescriptionsBatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | import java.io.File; 23 | 24 | public class GenerateRuleDescriptionsBatch { 25 | 26 | private static final String TEMPLATE_DIRECTORY = "json-checks/src/main/resources/org/sonar/l10n/json/rules/json/template/"; 27 | private static final String TARGET_DIRECTORY = "json-checks/target/classes/org/sonar/l10n/json/rules/json/"; 28 | 29 | private GenerateRuleDescriptionsBatch() { 30 | } 31 | 32 | public static void main(String... args) throws Exception { 33 | RuleDescriptionsGenerator ruleDescriptionsGenerator = new RuleDescriptionsGenerator(); 34 | File[] files = new File(TEMPLATE_DIRECTORY).listFiles(); 35 | for (File file : files) { 36 | ruleDescriptionsGenerator.generateHtmlRuleDescription(file.getPath(), TARGET_DIRECTORY + file.getName()); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/Tags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | public class Tags { 23 | 24 | public static final String CONVENTION = "convention"; 25 | public static final String BUG = "bug"; 26 | public static final String OBSOLETE = "obsolete"; 27 | public static final String PITFALL = "pitfall"; 28 | public static final String PUPPET = "puppet"; 29 | 30 | private Tags() { 31 | // This class only defines constants 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/generic/ParsingErrorCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.generic; 21 | 22 | import org.sonar.check.Priority; 23 | import org.sonar.check.Rule; 24 | import org.sonar.json.checks.Tags; 25 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitorCheck; 26 | import org.sonar.squidbridge.annotations.ActivatedByDefault; 27 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation; 28 | 29 | @Rule( 30 | key = "S2260", 31 | name = "JSON parser failure", 32 | priority = Priority.CRITICAL, 33 | tags = {Tags.BUG}) 34 | @ActivatedByDefault 35 | @SqaleConstantRemediation("5min") 36 | public class ParsingErrorCheck extends DoubleDispatchVisitorCheck { 37 | } 38 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/generic/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.checks.generic; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.checks; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/puppet/AbstractPuppetCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.puppet; 21 | 22 | import org.sonar.check.Priority; 23 | import org.sonar.check.Rule; 24 | import org.sonar.json.checks.Tags; 25 | import org.sonar.plugins.json.api.tree.JsonTree; 26 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitorCheck; 27 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation; 28 | 29 | @Rule( 30 | key = "puppet-deprecated-keys", 31 | name = "Deprecated keys should be removed from Puppet \"metadata.json\" files", 32 | priority = Priority.MAJOR, 33 | tags = {Tags.OBSOLETE, Tags.PUPPET}) 34 | @SqaleConstantRemediation("5min") 35 | public abstract class AbstractPuppetCheck extends DoubleDispatchVisitorCheck { 36 | 37 | @Override 38 | public void visitJson(JsonTree tree) { 39 | if ("metadata.json".equals(getContext().getFile().getName())) { 40 | super.visitJson(tree); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/puppet/PuppetDeprecatedKeysCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.puppet; 21 | 22 | import org.sonar.check.Priority; 23 | import org.sonar.check.Rule; 24 | import org.sonar.json.checks.Tags; 25 | import org.sonar.plugins.json.api.tree.KeyTree; 26 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation; 27 | 28 | @Rule( 29 | key = "puppet-deprecated-keys", 30 | name = "Deprecated keys should be removed from Puppet \"metadata.json\" files", 31 | priority = Priority.MAJOR, 32 | tags = {Tags.OBSOLETE, Tags.PUPPET}) 33 | @SqaleConstantRemediation("5min") 34 | public class PuppetDeprecatedKeysCheck extends AbstractPuppetCheck { 35 | 36 | @Override 37 | public void visitKey(KeyTree tree) { 38 | if ("types".equals(tree.actualText())) { 39 | addPreciseIssue(tree, "Remove this deprecated \"types\" key."); 40 | } else if ("checksums".equals(tree.actualText())) { 41 | addPreciseIssue(tree, "Remove this deprecated \"checksums\" key."); 42 | } else if ("description".equals(tree.actualText())) { 43 | addPreciseIssue(tree, "Replace this deprecated \"description\" key by the \"summary\" key."); 44 | } 45 | super.visitKey(tree); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /json-checks/src/main/java/org/sonar/json/checks/puppet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.checks.puppet; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/S1578.html: -------------------------------------------------------------------------------- 1 |

2 | Shared coding conventions allow teams to collaborate effectively. This rule checks that all file names match a 3 | provided regular expression. 4 |

5 |

As JSON files are used in a large variety of ways and by many frameworks, it might sometimes be tricky to enforce a 6 | strict file naming convention. However, the default regular expression has been designed to match as closely as 7 | possible the following guidelines: 8 |

9 |
    10 |
  • Suffix files with .json
  • 11 |
  • Only use letters, digits, '_' and '-' characters
  • 12 |
  • Refrain from using '_' and '-' characters. Only use them when mandatory.
  • 13 |
  • Extensively use Camel Case. For example, prefer: 14 |
    15 | myObject.json
    16 | 
    17 | to 18 |
    19 | myobject.json
    20 | my_object.json
    21 | 
    22 |
  • 23 |
24 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/S2260.html: -------------------------------------------------------------------------------- 1 |

2 | When the parser fails, it is possible to record the failure as an issue on the file. This way, not only is it 3 | possible to track the number of files that do not parse but also to easily find out why they do not parse. 4 |

5 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/bom-utf8-files.html: -------------------------------------------------------------------------------- 1 |

2 | As stated in the Unicode specifications, use of a Byte Order Mark (BOM) is neither required nor recommended for 3 | UTF-8 files. 4 |

5 | 6 |

See

7 | 11 | 12 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/empty-line-end-of-file.html: -------------------------------------------------------------------------------- 1 |

Some tools such as Git work better when files end with an empty line.

2 |

This rule simply generates an issue if it is missing.

3 |

For example, a Git diff looks like:

4 |
 5 | {
 6 |   "key": "value"
 7 | }
 8 | \ No newline at end of file
 9 | 
10 |

if the empty line is missing at the end of the file.

11 | 12 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/key-regular-expression.html: -------------------------------------------------------------------------------- 1 |

This rule template can be used to create rules which will be triggered when a key matches a given regular 2 | expression. 3 |

4 |

5 | For example, one can create a rule with the regular expression .*error.* to match all key containing 6 | "error". Note that, in order to match "error" regardless of the case, the (?i) modifier can be 7 | prepended to the expression, as in (?i).*error.*. 8 |

9 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-deprecated-keys.html: -------------------------------------------------------------------------------- 1 |

2 | The following keys are deprecated in Puppet metadata.json files: 3 |

4 |
    5 |
  • types: Should be removed
  • 6 |
  • checksums: Should be removed
  • 7 |
  • description: Should be replaced by the summary key
  • 8 |
9 | 10 |

See

11 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-duplicated-dependencies.html: -------------------------------------------------------------------------------- 1 |

2 | This rule checks for duplicated dependency entries in Puppet metadata.json files. Those duplicated 3 | dependencies should be merged. 4 |

5 | 6 |

Noncompliant Code Example

7 |
 8 | {
 9 |   ...
10 |   "dependencies": [
11 |     { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
12 |     { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
13 |     { "name": "puppetlabs/apt", "version_requirement": ">=1.1.0 <2.0.0" },
14 |     { "name": "puppetlabs/stdlib", "version_requirement": ">=4.2.0" }    # Noncompliant: Duplicated dependency
15 |   ]
16 |   ...
17 | }
18 | 
19 | 20 |

Compliant Solution

21 |
22 | {
23 |   ...
24 |   "dependencies": [
25 |     { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
26 |     { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
27 |     { "name": "puppetlabs/apt", "version_requirement": ">=1.1.0 <2.0.0" }
28 |   ]
29 |   ...
30 | }
31 | 
32 | 33 |

See

34 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-enforce-author-value.html: -------------------------------------------------------------------------------- 1 |

2 | This rule allows you to enforce a specific value for the author field in Puppet 3 | metadata.json files. 4 |

5 |

6 | Note that the rule is not triggered when no author key is defined. To enforce the definition of an 7 | author key, activate rule puppet-required-keys. 8 |

9 | 10 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-enforce-license-value.html: -------------------------------------------------------------------------------- 1 |

2 | This rule allows you to enforce a specific value for the license field in Puppet 3 | metadata.json files. 4 |

5 |

6 | Note that the rule is not triggered when no license key is defined. To enforce the definition of a 7 | license key, activate rule puppet-required-keys. 8 |

9 | 10 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-required-keys.html: -------------------------------------------------------------------------------- 1 |

2 | Every Puppet metadata.json file should define the following keys: 3 |

4 |
    5 |
  • name
  • 6 |
  • version
  • 7 |
  • author
  • 8 |
  • license
  • 9 |
  • summary
  • 10 |
  • source
  • 11 |
  • dependencies
  • 12 |
13 | 14 |

Noncompliant Code Example

15 | Missing author and license keys: 16 |
17 | {
18 |   "name": "examplecorp-mymodule",
19 |   "version": "0.0.1",
20 |   "summary": "A module for a thing",
21 |   "source": "https://github.com/examplecorp/examplecorp-mymodule",
22 |   "dependencies": [
23 |     { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
24 |     { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
25 |   ]
26 | }
27 | 
28 | 29 |

Compliant Solution

30 |
31 | {
32 |   "name": "examplecorp-mymodule",
33 |   "version": "0.0.1",
34 |   "author": "Pat",
35 |   "license": "Apache-2.0",
36 |   "summary": "A module for a thing",
37 |   "source": "https://github.com/examplecorp/examplecorp-mymodule",
38 |   "dependencies": [
39 |     { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
40 |     { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
41 |   ]
42 | }
43 | 
44 | 45 |

See

46 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-version.html: -------------------------------------------------------------------------------- 1 |

2 | Version management should comply with semantic version. 3 |

4 |

5 | Given a version number MAJOR.MINOR.PATCH, increment the: 6 |

7 |
    8 |
  • MAJOR version when you make incompatible API changes
  • 9 |
  • MINOR version when you add functionality in a backwards-compatible manner
  • 10 |
  • PATCH version when you make backwards-compatible bug fixes
  • 11 |
12 |

13 | This rule check the version format that should be made of 3 digits separated by dots: ^\d+\.\d+\.\d+$ 14 |

15 | 16 |

Noncompliant Version

17 |
18 | {
19 |   "version": "1.0",
20 |   "version": "1.0.0.2"
21 | }
22 | 
23 | 24 |

Compliant Version

25 |
26 | {
27 |   "version": "1.0.0",
28 |   "version": "1.0.2"
29 | }
30 | 
31 | -------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/tab-character.html: -------------------------------------------------------------------------------- 1 |

2 | Developers should not need to configure the tab width of their text editors in order to be able to read source code. 3 | So the use of tabulation character must be banned. 4 |

-------------------------------------------------------------------------------- /json-checks/src/main/resources/org/sonar/l10n/json/rules/json/template/puppet-license.html: -------------------------------------------------------------------------------- 1 |

2 | License should be either proprietary or one listed on the SPDX 3 | page. 4 |

5 | 6 |

Nocompliant Code Example

7 |
 8 | {
 9 |   ...
10 |   "license": blabla
11 |   ...
12 | }
13 | 
14 | 15 |

Compliant Solution

16 |
17 | {
18 |   ...
19 |   "license": "proprietary"
20 |   ...
21 | }
22 | 
23 | {
24 |   ...
25 |   "license": "LGPL-3.0"
26 |   ...
27 | }
28 | 
29 | 30 |

See

31 | 35 | 36 |

List of Licenses

37 | [[allLicenses]] -------------------------------------------------------------------------------- /json-checks/src/test/java/org/sonar/json/checks/CheckTestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks; 21 | 22 | import java.io.File; 23 | 24 | public class CheckTestUtils { 25 | 26 | private CheckTestUtils() { 27 | } 28 | 29 | public static File getTestFile(String relativePath) { 30 | return new File("src/test/resources/checks/" + relativePath); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /json-checks/src/test/java/org/sonar/json/checks/generic/BOMCheckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.generic; 21 | 22 | import com.google.common.base.Charsets; 23 | import org.junit.Test; 24 | import org.sonar.json.checks.CheckTestUtils; 25 | import org.sonar.json.checks.verifier.JSONCheckVerifier; 26 | 27 | public class BOMCheckTest { 28 | 29 | @Test 30 | public void should_find_a_BOM_in_UTF8_file_and_raise_an_issue() { 31 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf8WithBOM.json")) 32 | .next().withMessage("Remove the BOM.") 33 | .noMore(); 34 | } 35 | 36 | @Test 37 | public void should_find_a_BOM_in_UTF16_files_but_not_raise_any_issue() { 38 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf16BE.json"), Charsets.UTF_16BE) 39 | .noMore(); 40 | 41 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf16LE.json"), Charsets.UTF_16LE) 42 | .noMore(); 43 | } 44 | 45 | @Test 46 | public void should_not_find_a_BOM_in_UTF8_file_and_not_raise_any_issue() { 47 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("sample.json"), Charsets.UTF_8) 48 | .noMore(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /json-checks/src/test/java/org/sonar/json/checks/generic/MissingNewLineAtEndOfFileCheckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.generic; 21 | 22 | import org.junit.Test; 23 | import org.sonar.json.checks.CheckTestUtils; 24 | import org.sonar.json.checks.verifier.JSONCheckVerifier; 25 | 26 | public class MissingNewLineAtEndOfFileCheckTest { 27 | 28 | @Test 29 | public void should_have_an_empty_new_line_at_the_end_of_the_file_and_not_raise_any_issue() { 30 | JSONCheckVerifier.verify(new MissingNewLineAtEndOfFileCheck(), CheckTestUtils.getTestFile("newLineEndOfFile.json")) 31 | .noMore(); 32 | } 33 | 34 | @Test 35 | public void should_not_have_an_empty_new_line_at_the_end_of_the_file_and_raise_an_issue() { 36 | JSONCheckVerifier.verify(new MissingNewLineAtEndOfFileCheck(), CheckTestUtils.getTestFile("noNewLineEndOfFile.json")) 37 | .next().withMessage("Add an empty new line at the end of this file.") 38 | .noMore(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-checks/src/test/java/org/sonar/json/checks/generic/TabCharacterCheckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.generic; 21 | 22 | import org.junit.Test; 23 | import org.sonar.json.checks.CheckTestUtils; 24 | import org.sonar.json.checks.verifier.JSONCheckVerifier; 25 | 26 | public class TabCharacterCheckTest { 27 | 28 | @Test 29 | public void should_find_tab_characters_and_raise_an_issue() { 30 | JSONCheckVerifier.verify(new TabCharacterCheck(), CheckTestUtils.getTestFile("tabCharacter.json")) 31 | .next().withMessage("Replace all tab characters in this file by sequences of whitespaces.") 32 | .noMore(); 33 | } 34 | 35 | @Test 36 | public void should_not_find_tab_characters_and_not_raise_an_issue() { 37 | JSONCheckVerifier.verify(new TabCharacterCheck(), CheckTestUtils.getTestFile("sample.json")) 38 | .noMore(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-checks/src/test/java/org/sonar/json/checks/puppet/PuppetDeprecatedKeysCheckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.checks.puppet; 21 | 22 | import org.junit.Test; 23 | import org.sonar.json.checks.CheckTestUtils; 24 | import org.sonar.json.checks.verifier.JSONCheckVerifier; 25 | 26 | public class PuppetDeprecatedKeysCheckTest { 27 | 28 | @Test 29 | public void should_find_some_deprecated_keys_and_raise_some_issues() { 30 | JSONCheckVerifier.verify(new PuppetDeprecatedKeysCheck(), CheckTestUtils.getTestFile("puppet/deprecated-keys/metadata.json")) 31 | .next().startAtLine(4).startAtColumn(3).endAtLine(4).endAtColumn(16).withMessage("Replace this deprecated \"description\" key by the \"summary\" key.") 32 | .next().startAtLine(5).startAtColumn(3).endAtLine(5).endAtColumn(10).withMessage("Remove this deprecated \"types\" key.") 33 | .next().startAtLine(6).startAtColumn(3).endAtLine(6).endAtColumn(14).withMessage("Remove this deprecated \"checksums\" key.") 34 | .noMore(); 35 | } 36 | 37 | @Test 38 | public void should_not_raise_any_issues_because_it_is_not_a_metadata_json_file() { 39 | JSONCheckVerifier.verify(new PuppetDeprecatedKeysCheck(), CheckTestUtils.getTestFile("puppet/deprecated-keys/notmetadata.json")) 40 | .noMore(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/file-name.ko.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/keyRegularExpression.json: -------------------------------------------------------------------------------- 1 | { 2 | "mykey": {}, 3 | "abc" : [123, 234], 4 | "blabla_mykey_blabla" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "mykey": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/newLineEndOfFile.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/noNewLineEndOfFile.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/parsingError.json: -------------------------------------------------------------------------------- 1 | blabla... -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/author/custom/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/author/default-issue/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "author": [ 6 | "abc", 7 | "def" 8 | ], 9 | "license": "Apache-2.0", 10 | "summary": "A module for a thing", 11 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 14 | "tags": ["things", "stuff"], 15 | "operatingsystem_support": [ 16 | { 17 | "operatingsystem":"RedHat", 18 | "operatingsystemrelease":[ "5.0", "6.0" ] 19 | }, 20 | { 21 | "operatingsystem": "Ubuntu", 22 | "operatingsystemrelease": [ "12.04", "10.04" ] 23 | } 24 | ], 25 | "dependencies": [ 26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 28 | ] 29 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/author/default/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "John Doe", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/author/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "John Doe", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/dependencies/duplicated-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }, 24 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 25 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }, 26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 27 | ] 28 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/dependencies/invalid-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": "abc" 22 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/dependencies/no-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/dependencies/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": "abc" 22 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/dependencies/valid-dependencies/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/deprecated-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "description": "A module for a thing", 5 | "types": "blabla", 6 | "checksums": "blabla", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/deprecated-keys/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "description": "A module for a thing", 5 | "types": "blabla", 6 | "checksums": "blabla", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/invalid/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/match-required-value-custom/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/match-required-value/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "license": [ "blabla" ], 7 | "summary": "A module for a thing", 8 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 11 | "tags": ["things", "stuff"], 12 | "operatingsystem_support": [ 13 | { 14 | "operatingsystem":"RedHat", 15 | "operatingsystemrelease":[ "5.0", "6.0" ] 16 | }, 17 | { 18 | "operatingsystem": "Ubuntu", 19 | "operatingsystemrelease": [ "12.04", "10.04" ] 20 | } 21 | ], 22 | "dependencies": [ 23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 25 | ] 26 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/no-license/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "summary": "A module for a thing", 6 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 7 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 8 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 9 | "tags": ["things", "stuff"], 10 | "operatingsystem_support": [ 11 | { 12 | "operatingsystem":"RedHat", 13 | "operatingsystemrelease":[ "5.0", "6.0" ] 14 | }, 15 | { 16 | "operatingsystem": "Ubuntu", 17 | "operatingsystemrelease": [ "12.04", "10.04" ] 18 | } 19 | ], 20 | "dependencies": [ 21 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 22 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 23 | ] 24 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "blabla", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/two-licenses/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "license": "Apache-2.0", 7 | "summary": "A module for a thing", 8 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 11 | "tags": ["things", "stuff"], 12 | "operatingsystem_support": [ 13 | { 14 | "operatingsystem":"RedHat", 15 | "operatingsystemrelease":[ "5.0", "6.0" ] 16 | }, 17 | { 18 | "operatingsystem": "Ubuntu", 19 | "operatingsystemrelease": [ "12.04", "10.04" ] 20 | } 21 | ], 22 | "dependencies": [ 23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 25 | ] 26 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/valid-proprietary/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "proprietary", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/license/valid-spdx/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "LGPL-3.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/required-keys/empty-file/metadata.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/puppet/required-keys/empty-file/metadata.json -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/required-keys/missing-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "summary": "A module for a thing", 5 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 8 | "tags": ["things", "stuff"], 9 | "operatingsystem_support": [ 10 | { 11 | "operatingsystem":"RedHat", 12 | "operatingsystemrelease":[ "5.0", "6.0" ] 13 | }, 14 | { 15 | "operatingsystem": "Ubuntu", 16 | "operatingsystemrelease": [ "12.04", "10.04" ] 17 | } 18 | ], 19 | "dependencies": [ 20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 22 | ] 23 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/required-keys/no-missing-keys/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "author": "Pat", 5 | "license": "Apache-2.0", 6 | "summary": "A module for a thing", 7 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 10 | "tags": ["things", "stuff"], 11 | "operatingsystem_support": [ 12 | { 13 | "operatingsystem":"RedHat", 14 | "operatingsystemrelease":[ "5.0", "6.0" ] 15 | }, 16 | { 17 | "operatingsystem": "Ubuntu", 18 | "operatingsystemrelease": [ "12.04", "10.04" ] 19 | } 20 | ], 21 | "dependencies": [ 22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 24 | ] 25 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/required-keys/not-metadata-json-file/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "summary": "A module for a thing", 5 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 8 | "tags": ["things", "stuff"], 9 | "operatingsystem_support": [ 10 | { 11 | "operatingsystem":"RedHat", 12 | "operatingsystemrelease":[ "5.0", "6.0" ] 13 | }, 14 | { 15 | "operatingsystem": "Ubuntu", 16 | "operatingsystemrelease": [ "12.04", "10.04" ] 17 | } 18 | ], 19 | "dependencies": [ 20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 22 | ] 23 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/version/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "version": "0.1", 5 | "version": "1.0.1-beta", 6 | "version": "abc", 7 | "version": [ "0.1" ], 8 | "author": "Pat", 9 | "license": "Apache-2.0", 10 | "summary": "A module for a thing", 11 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 14 | "tags": ["things", "stuff"], 15 | "operatingsystem_support": [ 16 | { 17 | "operatingsystem":"RedHat", 18 | "operatingsystemrelease":[ "5.0", "6.0" ] 19 | }, 20 | { 21 | "operatingsystem": "Ubuntu", 22 | "operatingsystemrelease": [ "12.04", "10.04" ] 23 | } 24 | ], 25 | "dependencies": [ 26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 28 | ] 29 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/puppet/version/notmetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplecorp-mymodule", 3 | "version": "0.0.1", 4 | "version": "0.1", 5 | "version": "1.0.1-beta", 6 | "version": "abc", 7 | "author": "Pat", 8 | "license": "Apache-2.0", 9 | "summary": "A module for a thing", 10 | "source": "https://github.com/examplecorp/examplecorp-mymodule", 11 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule", 12 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues", 13 | "tags": ["things", "stuff"], 14 | "operatingsystem_support": [ 15 | { 16 | "operatingsystem":"RedHat", 17 | "operatingsystemrelease":[ "5.0", "6.0" ] 18 | }, 19 | { 20 | "operatingsystem": "Ubuntu", 21 | "operatingsystemrelease": [ "12.04", "10.04" ] 22 | } 23 | ], 24 | "dependencies": [ 25 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, 26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" } 27 | ] 28 | } -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "foo" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "abc": "\"wtf", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/tab-character.json~: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/tabCharacter.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [true, null], 4 | "abc" : false, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/utf16BE.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/utf16BE.json -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/utf16LE.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/utf16LE.json -------------------------------------------------------------------------------- /json-checks/src/test/resources/checks/utf8WithBOM.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-frontend/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.codehaus.sonar-plugins.json 7 | json 8 | 2.4-SNAPSHOT 9 | 10 | 11 | json-frontend 12 | SonarQube JSON Analyzer :: Frontend 13 | 14 | 15 | 16 | org.sonarsource.sonarqube 17 | sonar-plugin-api 18 | provided 19 | 20 | 21 | commons-lang 22 | commons-lang 23 | 24 | 25 | org.sonarsource.sslr 26 | sslr-core 27 | 28 | 29 | org.sonarsource.sslr-squid-bridge 30 | sslr-squid-bridge 31 | 32 | 33 | com.google.guava 34 | guava 35 | 36 | 37 | junit 38 | junit 39 | test 40 | 41 | 42 | org.sonarsource.sslr 43 | sslr-testing-harness 44 | test 45 | 46 | 47 | org.mockito 48 | mockito-all 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.jacoco 57 | jacoco-maven-plugin 58 | 59 | ${sonar.jacoco.reportPath} 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/parser/JSONParserBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import com.google.common.annotations.VisibleForTesting; 23 | import com.sonar.sslr.api.typed.ActionParser; 24 | 25 | import java.nio.charset.Charset; 26 | 27 | import org.sonar.plugins.json.api.tree.Tree; 28 | import org.sonar.sslr.grammar.GrammarRuleKey; 29 | 30 | public class JSONParserBuilder { 31 | 32 | private JSONParserBuilder() { 33 | } 34 | 35 | public static ActionParser createParser(Charset charset) { 36 | return createParser(charset, JSONLexicalGrammar.JSON); 37 | } 38 | 39 | @VisibleForTesting 40 | public static ActionParser createTestParser(Charset charset, GrammarRuleKey rootRule) { 41 | return createParser(charset, rootRule); 42 | } 43 | 44 | private static ActionParser createParser(Charset charset, GrammarRuleKey rootRule) { 45 | return new ActionParser<>( 46 | charset, 47 | JSONLexicalGrammar.createGrammar(), 48 | JSONGrammar.class, 49 | new TreeFactory(), 50 | new JSONNodeBuilder(), 51 | rootRule); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/parser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.parser; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/FalseTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import org.sonar.plugins.json.api.tree.SyntaxToken; 23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 24 | 25 | public class FalseTreeImpl extends LiteralTreeImpl { 26 | 27 | public FalseTreeImpl(SyntaxToken value) { 28 | super(value); 29 | } 30 | 31 | @Override 32 | public Kind getKind() { 33 | return Kind.FALSE; 34 | } 35 | 36 | @Override 37 | public void accept(DoubleDispatchVisitor visitor) { 38 | visitor.visitFalse(this); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/KeyTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import com.google.common.collect.Iterators; 23 | 24 | import java.util.Iterator; 25 | 26 | import org.sonar.plugins.json.api.tree.KeyTree; 27 | import org.sonar.plugins.json.api.tree.SyntaxToken; 28 | import org.sonar.plugins.json.api.tree.Tree; 29 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 30 | 31 | public class KeyTreeImpl extends JSONTree implements KeyTree { 32 | 33 | private final SyntaxToken key; 34 | 35 | public KeyTreeImpl(SyntaxToken key) { 36 | this.key = key; 37 | } 38 | 39 | @Override 40 | public Tree.Kind getKind() { 41 | return Tree.Kind.KEY; 42 | } 43 | 44 | @Override 45 | public Iterator childrenIterator() { 46 | return Iterators.singletonIterator(key); 47 | } 48 | 49 | @Override 50 | public String actualText() { 51 | return key.text().substring(1, key.text().length() - 1); 52 | } 53 | 54 | @Override 55 | public SyntaxToken value() { 56 | return key; 57 | } 58 | 59 | @Override 60 | public void accept(DoubleDispatchVisitor visitor) { 61 | visitor.visitKey(this); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/LiteralTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import com.google.common.collect.Iterators; 23 | 24 | import java.util.Iterator; 25 | 26 | import org.sonar.plugins.json.api.tree.LiteralTree; 27 | import org.sonar.plugins.json.api.tree.SyntaxToken; 28 | import org.sonar.plugins.json.api.tree.Tree; 29 | 30 | public abstract class LiteralTreeImpl extends JSONTree implements LiteralTree { 31 | 32 | private final SyntaxToken value; 33 | private final String text; 34 | 35 | public LiteralTreeImpl(SyntaxToken value) { 36 | this.value = value; 37 | text = value.text(); 38 | } 39 | 40 | @Override 41 | public Iterator childrenIterator() { 42 | return Iterators.singletonIterator(value); 43 | } 44 | 45 | @Override 46 | public SyntaxToken value() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public String text() { 52 | return text; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/NullTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import org.sonar.plugins.json.api.tree.SyntaxToken; 23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 24 | 25 | public class NullTreeImpl extends LiteralTreeImpl { 26 | 27 | public NullTreeImpl(SyntaxToken value) { 28 | super(value); 29 | } 30 | 31 | @Override 32 | public Kind getKind() { 33 | return Kind.NULL; 34 | } 35 | 36 | @Override 37 | public void accept(DoubleDispatchVisitor visitor) { 38 | visitor.visitNull(this); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/NumberTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import org.sonar.plugins.json.api.tree.SyntaxToken; 23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 24 | 25 | public class NumberTreeImpl extends LiteralTreeImpl { 26 | 27 | public NumberTreeImpl(SyntaxToken value) { 28 | super(value); 29 | } 30 | 31 | @Override 32 | public Kind getKind() { 33 | return Kind.NUMBER; 34 | } 35 | 36 | @Override 37 | public void accept(DoubleDispatchVisitor visitor) { 38 | visitor.visitNumber(this); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/PairTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import com.google.common.collect.Iterators; 23 | 24 | import java.util.Iterator; 25 | 26 | import org.sonar.plugins.json.api.tree.*; 27 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 28 | 29 | public class PairTreeImpl extends JSONTree implements PairTree { 30 | 31 | private final KeyTree key; 32 | private final SyntaxToken colon; 33 | private final ValueTree value; 34 | 35 | public PairTreeImpl(KeyTree key, SyntaxToken colon, ValueTree value) { 36 | this.key = key; 37 | this.colon = colon; 38 | this.value = value; 39 | } 40 | 41 | @Override 42 | public Kind getKind() { 43 | return Kind.PAIR; 44 | } 45 | 46 | @Override 47 | public Iterator childrenIterator() { 48 | return Iterators.forArray(key, colon, value); 49 | } 50 | 51 | @Override 52 | public KeyTree key() { 53 | return key; 54 | } 55 | 56 | @Override 57 | public SyntaxToken colon() { 58 | return colon; 59 | } 60 | 61 | @Override 62 | public ValueTree value() { 63 | return value; 64 | } 65 | 66 | @Override 67 | public void accept(DoubleDispatchVisitor visitor) { 68 | visitor.visitPair(this); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/StringTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import org.sonar.plugins.json.api.tree.StringTree; 23 | import org.sonar.plugins.json.api.tree.SyntaxToken; 24 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 25 | 26 | public class StringTreeImpl extends LiteralTreeImpl implements StringTree { 27 | 28 | public StringTreeImpl(SyntaxToken value) { 29 | super(value); 30 | } 31 | 32 | @Override 33 | public Kind getKind() { 34 | return Kind.STRING; 35 | } 36 | 37 | @Override 38 | public void accept(DoubleDispatchVisitor visitor) { 39 | visitor.visitString(this); 40 | } 41 | 42 | @Override 43 | public String actualText() { 44 | return text().substring(1, text().length() - 1); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/TrueTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import org.sonar.plugins.json.api.tree.SyntaxToken; 23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 24 | 25 | public class TrueTreeImpl extends LiteralTreeImpl { 26 | 27 | public TrueTreeImpl(SyntaxToken value) { 28 | super(value); 29 | } 30 | 31 | @Override 32 | public Kind getKind() { 33 | return Kind.TRUE; 34 | } 35 | 36 | @Override 37 | public void accept(DoubleDispatchVisitor visitor) { 38 | visitor.visitTrue(this); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/ValueTreeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.tree.impl; 21 | 22 | import com.google.common.collect.Iterators; 23 | 24 | import java.util.Iterator; 25 | 26 | import org.sonar.plugins.json.api.tree.Tree; 27 | import org.sonar.plugins.json.api.tree.ValueTree; 28 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 29 | 30 | public class ValueTreeImpl extends JSONTree implements ValueTree { 31 | 32 | private final Tree value; 33 | 34 | public ValueTreeImpl(Tree value) { 35 | this.value = value; 36 | } 37 | 38 | @Override 39 | public Kind getKind() { 40 | return Kind.VALUE; 41 | } 42 | 43 | @Override 44 | public Iterator childrenIterator() { 45 | return Iterators.singletonIterator(value); 46 | } 47 | 48 | @Override 49 | public void accept(DoubleDispatchVisitor visitor) { 50 | visitor.visitValue(this); 51 | } 52 | 53 | @Override 54 | public Tree value() { 55 | return value; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/tree/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.tree.impl; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/CharsetAwareVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.visitors; 21 | 22 | import java.nio.charset.Charset; 23 | 24 | @FunctionalInterface 25 | public interface CharsetAwareVisitor { 26 | 27 | void setCharset(Charset charset); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/JSONVisitorContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.visitors; 21 | 22 | import java.io.File; 23 | 24 | import org.sonar.plugins.json.api.tree.JsonTree; 25 | import org.sonar.plugins.json.api.visitors.TreeVisitorContext; 26 | 27 | public class JSONVisitorContext implements TreeVisitorContext { 28 | 29 | private final JsonTree tree; 30 | private final File file; 31 | 32 | public JSONVisitorContext(JsonTree tree, File file) { 33 | this.tree = tree; 34 | this.file = file; 35 | } 36 | 37 | @Override 38 | public JsonTree getTopTree() { 39 | return tree; 40 | } 41 | 42 | @Override 43 | public File getFile() { 44 | return file; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/metrics/LinesOfCodeVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.visitors.metrics; 21 | 22 | import com.google.common.collect.ImmutableList; 23 | import com.google.common.collect.Sets; 24 | 25 | import java.util.List; 26 | import java.util.Set; 27 | 28 | import org.sonar.json.tree.impl.InternalSyntaxToken; 29 | import org.sonar.plugins.json.api.tree.Tree; 30 | import org.sonar.plugins.json.api.visitors.SubscriptionVisitor; 31 | 32 | public class LinesOfCodeVisitor extends SubscriptionVisitor { 33 | 34 | private Set linesOfCode = Sets.newHashSet(); 35 | 36 | public LinesOfCodeVisitor(Tree tree) { 37 | linesOfCode.clear(); 38 | scanTree(tree); 39 | } 40 | 41 | @Override 42 | public List nodesToVisit() { 43 | return ImmutableList.of(Tree.Kind.TOKEN); 44 | } 45 | 46 | @Override 47 | public void visitNode(Tree tree) { 48 | InternalSyntaxToken token = (InternalSyntaxToken) tree; 49 | if (!token.isEOF() && !token.isBOM()) { 50 | linesOfCode.add(token.line()); 51 | } 52 | } 53 | 54 | public int getNumberOfLinesOfCode() { 55 | return linesOfCode.size(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/metrics/StatementsVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.visitors.metrics; 21 | 22 | import com.google.common.collect.ImmutableList; 23 | 24 | import java.util.List; 25 | 26 | import org.sonar.plugins.json.api.tree.Tree; 27 | import org.sonar.plugins.json.api.visitors.SubscriptionVisitor; 28 | 29 | public class StatementsVisitor extends SubscriptionVisitor { 30 | 31 | private int statements; 32 | 33 | public StatementsVisitor(Tree tree) { 34 | statements = 0; 35 | scanTree(tree); 36 | } 37 | 38 | @Override 39 | public List nodesToVisit() { 40 | return ImmutableList.of(Tree.Kind.PAIR); 41 | } 42 | 43 | @Override 44 | public void visitNode(Tree tree) { 45 | statements++; 46 | } 47 | 48 | public int getNumberOfStatements() { 49 | return statements; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/metrics/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.visitors.metrics; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/json/visitors/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.json.visitors; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/JSONCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api; 21 | 22 | import java.util.List; 23 | 24 | import org.sonar.plugins.json.api.tree.Tree; 25 | import org.sonar.plugins.json.api.visitors.TreeVisitorContext; 26 | import org.sonar.plugins.json.api.visitors.issue.FileIssue; 27 | import org.sonar.plugins.json.api.visitors.issue.Issue; 28 | import org.sonar.plugins.json.api.visitors.issue.LineIssue; 29 | import org.sonar.plugins.json.api.visitors.issue.PreciseIssue; 30 | 31 | public interface JSONCheck { 32 | 33 | PreciseIssue addPreciseIssue(Tree tree, String message); 34 | 35 | FileIssue addFileIssue(String message); 36 | 37 | LineIssue addLineIssue(int line, String message); 38 | 39 | List scanFile(TreeVisitorContext context); 40 | 41 | void validateParameters(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.plugins.json.api; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ArrayTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | import java.util.List; 23 | 24 | public interface ArrayTree extends Tree { 25 | 26 | SyntaxToken leftBracket(); 27 | 28 | List elements(); 29 | 30 | SyntaxToken rightBracket(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/JsonTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface JsonTree extends Tree { 23 | 24 | boolean hasByteOrderMark(); 25 | 26 | ValueTree value(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/KeyTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface KeyTree extends Tree { 23 | 24 | SyntaxToken value(); 25 | 26 | String actualText(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/LiteralTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface LiteralTree extends Tree { 23 | 24 | SyntaxToken value(); 25 | 26 | String text(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ObjectTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | import java.util.List; 23 | 24 | public interface ObjectTree extends Tree { 25 | 26 | SyntaxToken leftBrace(); 27 | 28 | List pairs(); 29 | 30 | SyntaxToken rightBrace(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/PairTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface PairTree extends Tree { 23 | 24 | KeyTree key(); 25 | 26 | SyntaxToken colon(); 27 | 28 | ValueTree value(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/StringTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface StringTree extends LiteralTree { 23 | 24 | /** 25 | * @return String without double quotes 26 | */ 27 | String actualText(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/SyntaxSpacing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface SyntaxSpacing extends Tree { 23 | 24 | String text(); 25 | 26 | int line(); 27 | 28 | int column(); 29 | 30 | int endLine(); 31 | 32 | int endColumn(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/SyntaxToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface SyntaxToken extends Tree { 23 | 24 | String text(); 25 | 26 | int line(); 27 | 28 | int column(); 29 | 30 | int endLine(); 31 | 32 | int endColumn(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/Tree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor; 23 | import org.sonar.sslr.grammar.GrammarRuleKey; 24 | 25 | public interface Tree { 26 | 27 | boolean is(Kind... kind); 28 | 29 | void accept(DoubleDispatchVisitor visitor); 30 | 31 | enum Kind implements GrammarRuleKey { 32 | 33 | JSON(JsonTree.class), 34 | ARRAY(ArrayTree.class), 35 | OBJECT(ObjectTree.class), 36 | PAIR(PairTree.class), 37 | VALUE(ValueTree.class), 38 | KEY(KeyTree.class), 39 | STRING(StringTree.class), 40 | NUMBER(LiteralTree.class), 41 | FALSE(LiteralTree.class), 42 | TRUE(LiteralTree.class), 43 | NULL(LiteralTree.class), 44 | TOKEN(SyntaxToken.class), 45 | SPACING(SyntaxSpacing.class); 46 | 47 | final Class associatedInterface; 48 | 49 | Kind(Class associatedInterface) { 50 | this.associatedInterface = associatedInterface; 51 | } 52 | 53 | public Class getAssociatedInterface() { 54 | return associatedInterface; 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ValueTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.tree; 21 | 22 | public interface ValueTree extends Tree { 23 | 24 | Tree value(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/tree/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.plugins.json.api.tree; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/TreeVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.visitors; 21 | 22 | public interface TreeVisitor { 23 | 24 | TreeVisitorContext getContext(); 25 | 26 | void scanTree(TreeVisitorContext context); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/TreeVisitorContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.visitors; 21 | 22 | import java.io.File; 23 | 24 | import org.sonar.plugins.json.api.tree.JsonTree; 25 | 26 | public interface TreeVisitorContext { 27 | 28 | /** 29 | * @return the top tree node of the current file AST representation. 30 | */ 31 | JsonTree getTopTree(); 32 | 33 | /** 34 | * @return the current file 35 | */ 36 | File getFile(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/issue/Issue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json.api.visitors.issue; 21 | 22 | import javax.annotation.Nullable; 23 | 24 | import org.sonar.plugins.json.api.JSONCheck; 25 | 26 | public interface Issue { 27 | 28 | JSONCheck check(); 29 | 30 | @Nullable 31 | Double cost(); 32 | 33 | Issue cost(double cost); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/issue/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.plugins.json.api.visitors.issue; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.plugins.json.api.visitors; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/BOMTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class BOMTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public BOMTreeTest() { 27 | super(JSONLexicalGrammar.BOM); 28 | } 29 | 30 | @Test 31 | public void bom() { 32 | checkParsed("\ufeff"); 33 | } 34 | 35 | @Test 36 | public void notBom() { 37 | checkNotParsed("\"\\ufeff\""); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/ColonTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class ColonTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public ColonTreeTest() { 27 | super(JSONLexicalGrammar.COLON, ":"); 28 | } 29 | 30 | @Test 31 | public void colon() { 32 | checkParsed(":"); 33 | checkParsed(" :"); 34 | checkParsed(" :"); 35 | } 36 | 37 | @Test 38 | public void notColon() { 39 | checkNotParsed("="); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/CommaTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class CommaTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public CommaTreeTest() { 27 | super(JSONLexicalGrammar.COMMA, ","); 28 | } 29 | 30 | @Test 31 | public void comma() { 32 | checkParsed(","); 33 | checkParsed(" ,"); 34 | checkParsed(" ,"); 35 | } 36 | 37 | @Test 38 | public void notComma() { 39 | checkNotParsed(":"); 40 | checkNotParsed(";"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/CommonJsonTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import com.google.common.base.Charsets; 23 | import com.google.common.io.Files; 24 | import com.sonar.sslr.api.typed.ActionParser; 25 | import org.sonar.plugins.json.api.tree.Tree; 26 | 27 | import java.io.File; 28 | 29 | import static org.junit.Assert.fail; 30 | 31 | public abstract class CommonJsonTreeTest { 32 | 33 | private final ActionParser parser; 34 | 35 | public CommonJsonTreeTest(JSONLexicalGrammar ruleKey) { 36 | parser = JSONParserBuilder.createTestParser(Charsets.UTF_8, ruleKey); 37 | } 38 | 39 | public ActionParser parser() { 40 | return parser; 41 | } 42 | 43 | public void checkNotParsed(String toParse) { 44 | try { 45 | parser.parse(toParse); 46 | } catch (Exception e) { 47 | return; 48 | } 49 | fail("Did not throw a RecognitionException as expected."); 50 | } 51 | 52 | public void checkNotParsed(File file) { 53 | try { 54 | parser.parse(Files.toString(file, Charsets.UTF_8)); 55 | } catch (Exception e) { 56 | return; 57 | } 58 | fail("Did not throw a RecognitionException as expected."); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/CommonSyntaxTokenTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.sonar.plugins.json.api.tree.SyntaxToken; 23 | 24 | import static org.fest.assertions.Assertions.assertThat; 25 | 26 | public abstract class CommonSyntaxTokenTreeTest extends CommonJsonTreeTest { 27 | 28 | private String expectedText; 29 | 30 | public CommonSyntaxTokenTreeTest(JSONLexicalGrammar ruleKey) { 31 | super(ruleKey); 32 | this.expectedText = null; 33 | } 34 | 35 | public CommonSyntaxTokenTreeTest(JSONLexicalGrammar ruleKey, String expectedText) { 36 | super(ruleKey); 37 | this.expectedText = expectedText; 38 | } 39 | 40 | public void checkParsed(String toParse, String expected) { 41 | SyntaxToken token = (SyntaxToken) parser().parse(toParse); 42 | assertThat(token.text()).isEqualTo(expected); 43 | } 44 | 45 | public void checkParsed(String toParse) { 46 | checkParsed( 47 | toParse, 48 | expectedText != null ? expectedText : toParse); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/FalseTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class FalseTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public FalseTreeTest() { 27 | super(JSONLexicalGrammar.FALSE, "false"); 28 | } 29 | 30 | @Test 31 | public void isFalse() { 32 | checkParsed("false"); 33 | checkParsed(" false"); 34 | checkParsed(" false"); 35 | } 36 | 37 | @Test 38 | public void notFalse() { 39 | checkNotParsed("FALSE"); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/LeftBraceTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class LeftBraceTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public LeftBraceTreeTest() { 27 | super(JSONLexicalGrammar.LEFT_BRACE, "{"); 28 | } 29 | 30 | @Test 31 | public void leftBrace() { 32 | checkParsed("{"); 33 | checkParsed(" {"); 34 | checkParsed(" {"); 35 | } 36 | 37 | @Test 38 | public void notLeftBrace() { 39 | checkNotParsed("["); 40 | checkNotParsed("}"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/LeftBracketTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class LeftBracketTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public LeftBracketTreeTest() { 27 | super(JSONLexicalGrammar.LEFT_BRACKET, "["); 28 | } 29 | 30 | @Test 31 | public void leftBracket() { 32 | checkParsed("["); 33 | checkParsed(" ["); 34 | checkParsed(" ["); 35 | } 36 | 37 | @Test 38 | public void notLeftBracket() { 39 | checkNotParsed("]"); 40 | checkNotParsed("{"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/NullTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class NullTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public NullTreeTest() { 27 | super(JSONLexicalGrammar.NULL, "null"); 28 | } 29 | 30 | @Test 31 | public void isNull() { 32 | checkParsed("null"); 33 | checkParsed(" null", "null"); 34 | checkParsed(" null", "null"); 35 | } 36 | 37 | @Test 38 | public void notNull() { 39 | checkNotParsed("NULL"); 40 | checkNotParsed("\"NULL\""); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/RightBraceTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import com.google.common.base.Charsets; 23 | import org.junit.Test; 24 | import org.sonar.plugins.json.api.tree.SyntaxToken; 25 | 26 | public class RightBraceTreeTest extends CommonSyntaxTokenTreeTest { 27 | 28 | public RightBraceTreeTest() { 29 | super(JSONLexicalGrammar.RIGHT_BRACE, "}"); 30 | } 31 | 32 | @Test 33 | public void rightBrace() { 34 | checkParsed("}"); 35 | checkParsed(" }"); 36 | checkParsed(" }"); 37 | } 38 | 39 | @Test 40 | public void notRightBrace() { 41 | checkNotParsed("{"); 42 | checkNotParsed("]"); 43 | } 44 | 45 | private SyntaxToken parse(String toParse) { 46 | return (SyntaxToken) JSONParserBuilder 47 | .createTestParser(Charsets.UTF_8, JSONLexicalGrammar.RIGHT_BRACE) 48 | .parse(toParse); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/RightBracketTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class RightBracketTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public RightBracketTreeTest() { 27 | super(JSONLexicalGrammar.RIGHT_BRACKET, "]"); 28 | } 29 | 30 | @Test 31 | public void rightBracket() { 32 | checkParsed("]"); 33 | checkParsed(" ]"); 34 | checkParsed(" ]"); 35 | } 36 | 37 | @Test 38 | public void notRightBracket() { 39 | checkNotParsed("["); 40 | checkNotParsed("}"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/parser/TrueTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.parser; 21 | 22 | import org.junit.Test; 23 | 24 | public class TrueTreeTest extends CommonSyntaxTokenTreeTest { 25 | 26 | public TrueTreeTest() { 27 | super(JSONLexicalGrammar.TRUE, "true"); 28 | } 29 | 30 | @Test 31 | public void isTrue() { 32 | checkParsed("true"); 33 | checkParsed(" true", "true"); 34 | checkParsed(" true", "true"); 35 | } 36 | 37 | @Test 38 | public void notTrue() { 39 | checkNotParsed("TRUE"); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /json-frontend/src/test/java/org/sonar/json/visitors/metrics/MetricsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.json.visitors.metrics; 21 | 22 | import com.google.common.base.Charsets; 23 | import com.sonar.sslr.api.typed.ActionParser; 24 | import org.junit.Test; 25 | import org.sonar.json.parser.JSONParserBuilder; 26 | import org.sonar.plugins.json.api.tree.Tree; 27 | 28 | import java.io.File; 29 | 30 | import static org.fest.assertions.Assertions.assertThat; 31 | 32 | public class MetricsTest { 33 | 34 | private static final ActionParser PARSER = JSONParserBuilder.createParser(Charsets.UTF_8); 35 | 36 | @Test 37 | public void metrics() { 38 | String path = "src/test/resources/metrics.json"; 39 | Tree tree = PARSER.parse(new File(path)); 40 | assertMetrics(tree); 41 | } 42 | 43 | @Test 44 | public void metrics_UTF8_file_with_BOM() { 45 | String path = "src/test/resources/metricsUtf8WithBom.json"; 46 | Tree tree = PARSER.parse(new File(path)); 47 | assertMetrics(tree); 48 | } 49 | 50 | private void assertMetrics(Tree tree) { 51 | assertThat(new LinesOfCodeVisitor(tree).getNumberOfLinesOfCode()).isEqualTo(6); 52 | assertThat(new StatementsVisitor(tree).getNumberOfStatements()).isEqualTo(7); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /json-frontend/src/test/resources/file1.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-frontend/src/test/resources/metrics.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /json-frontend/src/test/resources/metricsUtf8WithBom.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } 8 | 9 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONLanguage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.sonar.api.resources.AbstractLanguage; 23 | 24 | public class JSONLanguage extends AbstractLanguage { 25 | 26 | public static final String KEY = "json"; 27 | 28 | public JSONLanguage() { 29 | super(KEY, "JSON"); 30 | } 31 | 32 | @Override 33 | public String[] getFileSuffixes() { 34 | return new String[] {"json"}; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.sonar.api.Plugin; 23 | 24 | public class JSONPlugin implements Plugin { 25 | 26 | @Override 27 | public void define(Context context) { 28 | context.addExtensions( 29 | JSONLanguage.class, 30 | JSONSquidSensor.class, 31 | JSONProfile.class, 32 | JSONRulesDefinition.class); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.sonar.api.profiles.ProfileDefinition; 23 | import org.sonar.api.profiles.RulesProfile; 24 | import org.sonar.api.rules.RuleFinder; 25 | import org.sonar.api.utils.ValidationMessages; 26 | import org.sonar.json.checks.CheckList; 27 | import org.sonar.squidbridge.annotations.AnnotationBasedProfileBuilder; 28 | 29 | public class JSONProfile extends ProfileDefinition { 30 | 31 | private final RuleFinder ruleFinder; 32 | 33 | public static final String SONARQUBE_WAY_PROFILE_NAME = "SonarQube Way"; 34 | 35 | public JSONProfile(RuleFinder ruleFinder) { 36 | this.ruleFinder = ruleFinder; 37 | } 38 | 39 | @Override 40 | public RulesProfile createProfile(ValidationMessages messages) { 41 | AnnotationBasedProfileBuilder annotationBasedProfileBuilder = new AnnotationBasedProfileBuilder(ruleFinder); 42 | return annotationBasedProfileBuilder.build( 43 | CheckList.REPOSITORY_KEY, 44 | SONARQUBE_WAY_PROFILE_NAME, 45 | JSONLanguage.KEY, 46 | CheckList.getChecks(), 47 | messages); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONRulesDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.sonar.api.server.rule.RulesDefinition; 23 | import org.sonar.json.checks.CheckList; 24 | import org.sonar.squidbridge.annotations.AnnotationBasedRulesDefinition; 25 | 26 | public class JSONRulesDefinition implements RulesDefinition { 27 | 28 | @Override 29 | public void define(Context context) { 30 | NewRepository repository = context 31 | .createRepository(JSONLanguage.KEY, JSONLanguage.KEY) 32 | .setName(CheckList.REPOSITORY_NAME); 33 | 34 | new AnnotationBasedRulesDefinition(repository, JSONLanguage.KEY).addRuleClasses(false, CheckList.getChecks()); 35 | repository.done(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/main/java/org/sonar/plugins/json/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package org.sonar.plugins.json; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; 24 | 25 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONLanguageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.fest.assertions.Assertions.assertThat; 25 | 26 | public class JSONLanguageTest { 27 | 28 | @Test 29 | public void language_key_and_name() { 30 | JSONLanguage json = new JSONLanguage(); 31 | assertThat(json.getKey()).isEqualTo("json"); 32 | assertThat(json.getName()).isEqualTo("JSON"); 33 | } 34 | 35 | @Test 36 | public void default_file_suffix() { 37 | JSONLanguage json = new JSONLanguage(); 38 | assertThat(json.getFileSuffixes()).containsOnly("json"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.junit.Test; 23 | import org.sonar.api.Plugin; 24 | import org.sonar.api.utils.Version; 25 | 26 | import static org.fest.assertions.Assertions.assertThat; 27 | 28 | public class JSONPluginTest { 29 | 30 | @Test 31 | public void should_get_the_right_version() { 32 | Plugin.Context context = new Plugin.Context(Version.create(5, 6)); 33 | new JSONPlugin().define(context); 34 | assertThat(context.getSonarQubeVersion().major()).isEqualTo(5); 35 | assertThat(context.getSonarQubeVersion().minor()).isEqualTo(6); 36 | } 37 | 38 | @Test 39 | public void should_get_the_right_number_of_extensions() { 40 | Plugin.Context context = new Plugin.Context(Version.create(5, 6)); 41 | new JSONPlugin().define(context); 42 | assertThat(context.getExtensions()).hasSize(4); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONRulesDefinitionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube JSON Analyzer 3 | * Copyright (C) 2015-2017 David RACODON 4 | * david.racodon@gmail.com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.json; 21 | 22 | import org.junit.Test; 23 | import org.sonar.api.server.rule.RulesDefinition; 24 | import org.sonar.check.Rule; 25 | import org.sonar.json.checks.CheckList; 26 | import org.sonar.json.checks.generic.FileNameCheck; 27 | 28 | import static org.fest.assertions.Assertions.assertThat; 29 | 30 | public class JSONRulesDefinitionTest { 31 | 32 | @Test 33 | public void test() { 34 | JSONRulesDefinition rulesDefinition = new JSONRulesDefinition(); 35 | RulesDefinition.Context context = new RulesDefinition.Context(); 36 | rulesDefinition.define(context); 37 | RulesDefinition.Repository repository = context.repository("json"); 38 | 39 | assertThat(repository.name()).isEqualTo("SonarQube"); 40 | assertThat(repository.language()).isEqualTo("json"); 41 | assertThat(repository.rules()).hasSize(CheckList.getChecks().size()); 42 | 43 | RulesDefinition.Rule fileNameRule = repository.rule(FileNameCheck.class.getAnnotation(Rule.class).key()); 44 | assertThat(fileNameRule).isNotNull(); 45 | assertThat(fileNameRule.name()).isEqualTo(FileNameCheck.class.getAnnotation(Rule.class).name()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/resources/parsingError.json: -------------------------------------------------------------------------------- 1 | blabla... -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/resources/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } -------------------------------------------------------------------------------- /sonar-json-plugin/src/test/resources/sampleUTF8WithBOM.json: -------------------------------------------------------------------------------- 1 | { 2 | "def": {}, 3 | "abc" : [123, 234], 4 | "abc" : 123, 5 | 6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]} 7 | } -------------------------------------------------------------------------------- /travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | mvn -B clean install -Pits -Dsonar.runtimeVersion=$SQ_VERSION 6 | 7 | if [ "$SQ_VERSION" == "LTS" ]; then 8 | 9 | mvnCommand='mvn -B sonar:sonar' 10 | commonArgs="-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.organization=racodond-github" 11 | githubArgs="-Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST -Dsonar.github.repository=$TRAVIS_REPO_SLUG -Dsonar.github.oauth=$GITHUB_TOKEN" 12 | branchArgs='' 13 | 14 | if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then 15 | if [ "$TRAVIS_BRANCH" != "master" ]; then 16 | branchArgs="-Dsonar.branch.name=$TRAVIS_BRANCH -Dsonar.branch.target=master" 17 | fi 18 | eval $mvnCommand $commonArgs $branchArgs 19 | else 20 | eval $mvnCommand $commonArgs $githubArgs 21 | fi 22 | 23 | fi 24 | --------------------------------------------------------------------------------