├── .editorconfig ├── .gitignore ├── .scalafmt.conf ├── .travis.yml ├── LICENSE ├── README.md ├── build.sbt ├── doc └── hooks │ ├── install-hooks.sh │ └── pre-push ├── project ├── Configuration.scala ├── build.properties └── plugins.sbt ├── scalastyle-config.xml └── src ├── main └── scala │ └── tv │ └── codely │ └── scala_bootstrap │ └── Codelyber.scala └── test └── scala └── tv └── codely └── scala_bootstrap └── CodelyberTest.scala /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.scala] 13 | indent_size = 2 14 | indent_style = space 15 | 16 | [*.md] 17 | trim_trailing_whitespace = false 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # scala 2 | *.class 3 | *.log 4 | 5 | # sbt 6 | .cache 7 | .history 8 | .lib/ 9 | dist/* 10 | target/ 11 | lib_managed/ 12 | src_managed/ 13 | project/boot/ 14 | project/plugins/project/ 15 | native/ -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | style = defaultWithAlign 2 | 3 | maxColumn = 120 4 | 5 | project.excludeFilters = ["target/"] 6 | 7 | # Only format files tracked by git. 8 | project.git = true 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | 3 | scala: 4 | - 2.12.4 5 | 6 | jdk: 7 | - oraclejdk8 8 | 9 | # These directories are cached to S3 at the end of the build 10 | cache: 11 | directories: 12 | - $HOME/.ivy2/cache 13 | - $HOME/.sbt/boot/ 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2017 CodelyTV staff@codely.tv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scala Bootstrap (base / project skeleton) 2 | 3 | > [!IMPORTANT] 4 | > Project deprecated in favor of [Codely Scala Basic Skeleton (powered by Giter 8)](https://github.com/CodelyTV/scala-basic-skeleton.g8) 5 | 6 | [![Software License][ico-license]][link-license] 7 | [![Build Status][ico-travis]][link-travis] 8 | 9 | ## Introduction 10 | 11 | This is a repository intended to serve as a starting point if you want to bootstrap a project in Scala. 12 | 13 | It could be useful if you want to start from scratch a kata or a little exercise or project. The idea is that you don't have to worry about the boilerplate, just clone this repo and there you go: 14 | * Latest versions of Scala, SBT and ScalaTest in order to practice with them 15 | * Best practices applied: 16 | * [`README.md`][link-readme] (badges included) 17 | * [`LICENSE`][link-license] 18 | * [`build.sbt`][link-build-sbt] 19 | * [`scalastyle-config.xml`][link-scalastyle-config] 20 | * [`.scalafmt.conf`][link-scalafmt-config] 21 | * [`.gitignore`][link-gitignore] 22 | * [`.editorconfig`][link-editorconfig] 23 | * [`.travis.yml`][link-travis-yml] 24 | 25 | ## How To Start 26 | 27 | [Video screencast](http://codely.tv/screencasts/entorno-scala/) (in Spanish) 28 | 29 | 1. Clone this repository `git clone https://github.com/CodelyTV/scala_bootstrap`. 30 | 2. Run [SBT](http://www.scala-sbt.org/) on the project directory `sbt`. 31 | 3. Run the [scalatests](http://www.scalatest.org/) with `t`. 32 | 4. Check the [scalastyle](http://www.scalastyle.org/) in the production code with `s` and use the `ts` command to check the test code style. 33 | 5. Check the [scalaFmt](http://scalafmt.org) with `tf` command to check the code style and apply guidelines with `f`. 34 | 6. Start your project! 35 | 36 | ## Pre-push Git hook 37 | 38 | There's one Git hook included. It's inside the `doc/hooks` folder and it will run the `prep` SBT task before pushing to any remote. 39 | 40 | This `prep` task is intended to run all the checks you consider before pushing. At this very moment, it try to compile and check the code style rules with ScalaStyle and ScalaFmt. 41 | 42 | You can define what this task does just modifying the `prep` task in the `build.sbt` file. We like the approach of just running 1 single SBT task as the hook instead of multiple tasks because it's more efficient (the hook doesn't has to run SBT multiple times), and also because this way we can control the pre push tasks just with the SBT alias defined at the `build.sbt` without altering the hooks. 43 | 44 | If you want to install this hook, just `cd doc/hooks` and run `./install-hooks.sh`. 45 | 46 | ## Other programming languages 47 | 48 | * [Scala g8 template](https://github.com/CodelyTV/scala-bootstrap-template.g8) Useful to bootstrap your project with the `sbt new` command! 49 | * [PHP](https://github.com/CodelyTV/php-bootstrap) 50 | * [Scala](https://github.com/CodelyTV/scala_bootstrap) 51 | 52 | ## About 53 | 54 | This hopefully helpful utility has been developed by [CodelyTV][link-author] and [contributors][link-contributors]. 55 | 56 | We'll try to maintain this project as simple as possible, but Pull Requests are welcomed! 57 | 58 | ## License 59 | 60 | The MIT License (MIT). Please see [License File][link-license] for more information. 61 | 62 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 63 | [ico-travis]: https://img.shields.io/travis/CodelyTV/scala_bootstrap/master.svg?style=flat-square 64 | 65 | [link-license]: LICENSE 66 | [link-travis]: https://travis-ci.org/CodelyTV/scala_bootstrap 67 | [link-readme]: README.md 68 | [link-build-sbt]: build.sbt 69 | [link-scalastyle-config]: scalastyle-config.xml 70 | [link-scalafmt-config]: .scalafmt.conf 71 | [link-gitignore]: .gitignore 72 | [link-editorconfig]: .editorconfig 73 | [link-travis-yml]: .travis.yml 74 | [link-author]: https://github.com/CodelyTV 75 | [link-contributors]: ../../contributors 76 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | /** ********* PROJECT INFO ******************/ 2 | name := "scala_bootstrap" 3 | version := "1.1.1" 4 | 5 | /** ********* PROJECT SETTINGS ******************/ 6 | Configuration.settings 7 | 8 | /** ********* PROD DEPENDENCIES *****************/ 9 | libraryDependencies ++= Seq( 10 | "com.github.nscala-time" %% "nscala-time" % "2.16.0", 11 | "com.lihaoyi" %% "pprint" % "0.5.2" 12 | ) 13 | 14 | /** ********* TEST DEPENDENCIES *****************/ 15 | libraryDependencies ++= Seq( 16 | "org.scalatest" %% "scalatest" % "3.0.1" % Test, 17 | "org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % Test 18 | ) 19 | 20 | /** ********* COMMANDS ALIASES ******************/ 21 | addCommandAlias("t", "test") 22 | addCommandAlias("to", "testOnly") 23 | addCommandAlias("tq", "testQuick") 24 | addCommandAlias("tsf", "testShowFailed") 25 | 26 | addCommandAlias("c", "compile") 27 | addCommandAlias("tc", "test:compile") 28 | 29 | addCommandAlias("s", "scalastyle") 30 | addCommandAlias("ts", "test:scalastyle") 31 | 32 | addCommandAlias("f", "scalafmt") // Format all files according to ScalaFmt 33 | addCommandAlias("ft", "scalafmtTest") // Test if all files are formatted according to ScalaFmt 34 | 35 | addCommandAlias("prep", ";c;tc;s;ts;ft") // All the needed tasks before running the test 36 | -------------------------------------------------------------------------------- /doc/hooks/install-hooks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd "$(dirname "$0")/../.." 4 | 5 | rm -rf .git/hooks 6 | 7 | ln -s ../doc/hooks .git/hooks 8 | sudo chmod -R 777 doc/hooks/* 9 | -------------------------------------------------------------------------------- /doc/hooks/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Checks if locally staged changes are formatted properly ignoring non-staged changes. 4 | # Install it with the `install-hooks.sh` script 5 | # Based on: https://gist.github.com/cvogt/2676ed6c6d1abafa3d6a 6 | 7 | PATH=$PATH:/usr/local/bin:/usr/local/sbin 8 | 9 | echo "" 10 | echo "Running pre-push hook… (you can omit this with --no-verify, but don't)" 11 | 12 | echo "* Moving to the project directory…" 13 | _DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 14 | DIR=$( echo $_DIR | sed 's/\/.git\/hooks$//' ) 15 | 16 | echo "* Stashing non-staged changes so we avoid checking them…" 17 | git diff --quiet 18 | hadNoNonStagedChanges=$? 19 | 20 | if ! [ $hadNoNonStagedChanges -eq 0 ] 21 | then 22 | git stash --keep-index -u > /dev/null 23 | fi 24 | 25 | echo "* Checking pre push conditions ('prep' SBT task)…" 26 | sbt prep > /dev/null 27 | canPush=$? 28 | 29 | if [ $canPush -ne 0 ] 30 | then 31 | echo " [KO] Error :(" 32 | fi 33 | 34 | echo "* Applying the stash with the non-staged changes…" 35 | if ! [ $hadNoNonStagedChanges -eq 0 ] 36 | then 37 | sleep 1 && git stash pop --index > /dev/null & # sleep because otherwise commit fails when this leads to a merge conflict 38 | fi 39 | 40 | # Final result 41 | echo "" 42 | 43 | if [ $canPush -eq 0 ] 44 | then 45 | echo "[OK] Your code will be pushed young Padawan" 46 | exit 0 47 | else 48 | echo "[KO] Cancelling push due to test code style error (run 'sbt prep' for more information)" 49 | exit 1 50 | fi 51 | -------------------------------------------------------------------------------- /project/Configuration.scala: -------------------------------------------------------------------------------- 1 | import sbt.{Tests, _} 2 | import sbt.Keys._ 3 | 4 | object Configuration { 5 | val settings = Seq( 6 | organization := "tv.codely", 7 | scalaVersion := "2.12.4", 8 | // Compiler options 9 | scalacOptions ++= Seq( 10 | "-deprecation", // Warnings deprecation 11 | "-feature", // Advise features 12 | "-unchecked", // More warnings. Strict 13 | "-Xlint", // More warnings when compiling 14 | "-Xfatal-warnings", // Warnings became errors 15 | "-Ywarn-dead-code", 16 | "-Ywarn-unused", 17 | "-Ywarn-unused-import", 18 | "-Xcheckinit" // Check against early initialization 19 | ), 20 | scalacOptions in run in Compile -= "-Xcheckinit", // Remove it in production because it's expensive 21 | javaOptions += "-Duser.timezone=UTC", 22 | // Test options 23 | parallelExecution in Test := false, 24 | testForkedParallel in Test := false, 25 | fork in Test := true, 26 | testOptions in Test ++= Seq( 27 | Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/test-reports"), // Save test reports 28 | Tests.Argument("-oDF") // Show full stack traces and time spent in each test 29 | ) 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.0.2 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.2.0") 2 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") 3 | -------------------------------------------------------------------------------- /scalastyle-config.xml: -------------------------------------------------------------------------------- 1 | 17 | 39 | 40 | 41 | Scalastyle standard configuration 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | ARROW, EQUALS, ELSE, TRY, CATCH, FINALLY, LARROW, RARROW 134 | 135 | 136 | 137 | 138 | 139 | ARROW, EQUALS, COMMA, COLON, IF, ELSE, DO, WHILE, FOR, MATCH, TRY, CATCH, FINALLY, 140 | LARROW, RARROW 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | ^FunSuite[A-Za-z]*$ 152 | 153 | Tests must extend org.apache.spark.SparkFunSuite instead. 154 | 155 | 156 | 157 | 158 | 159 | ^println$ 160 | 161 | 165 | 166 | 167 | 168 | 169 | @VisibleForTesting 170 | 171 | 174 | 175 | 176 | 177 | 178 | Runtime\.getRuntime\.addShutdownHook 179 | 180 | 188 | 189 | 190 | 191 | 192 | Class\.forName 193 | 194 | 201 | 202 | 203 | 204 | 205 | 206 | JavaConversions 207 | 208 | Instead of importing implicits in scala.collection.JavaConversions._, import 209 | scala.collection.JavaConverters._ and use .asScala / .asJava methods 210 | 211 | 212 | 213 | 214 | 215 | java,scala,play,3rdParty,codely 216 | javax?\..* 217 | scala\..* 218 | play\..* 219 | (?!tv\.codely\.).* 220 | tv\.codely\..* 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 232 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 249 | 250 | COLON, COMMA 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 800> 283 | 284 | 285 | 286 | 287 | 288 | 289 | 30 290 | 291 | 292 | 293 | 294 | 295 | 296 | 10 297 | 298 | 299 | 300 | 301 | 302 | 303 | 50 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | -1,0,1,2,3 319 | 320 | 321 | 322 | 323 | -------------------------------------------------------------------------------- /src/main/scala/tv/codely/scala_bootstrap/Codelyber.scala: -------------------------------------------------------------------------------- 1 | package tv.codely.scala_bootstrap 2 | 3 | case class Codelyber(name: String) { 4 | def greet(): String = "Hello" 5 | } 6 | -------------------------------------------------------------------------------- /src/test/scala/tv/codely/scala_bootstrap/CodelyberTest.scala: -------------------------------------------------------------------------------- 1 | package tv.codely.scala_bootstrap 2 | 3 | import org.scalatest._ 4 | import org.scalatest.Matchers._ 5 | 6 | final class CodelyberTest extends WordSpec with GivenWhenThen { 7 | 8 | "Codelyber" should { 9 | "say hello" in { 10 | Given("a Codelyber") 11 | 12 | val codelyber = Codelyber("Javi") 13 | 14 | When("we ask him to greet") 15 | 16 | val greeting = codelyber.greet() 17 | 18 | Then("he should say hello") 19 | 20 | greeting shouldBe "Hello" 21 | } 22 | } 23 | } 24 | --------------------------------------------------------------------------------