Skip to content

Commit

Permalink
feature: Update rubocop to 1.9.1 :breaking:
Browse files Browse the repository at this point in the history
- Remove outdated rubocop-github
- Move docker creation completely inside Dockerfile
- Move docs in /docs instead of /src/main/resources/docs
  • Loading branch information
lolgab committed Feb 2, 2021
1 parent d506d60 commit c8e6aee
Show file tree
Hide file tree
Showing 793 changed files with 7,801 additions and 1,163 deletions.
16 changes: 7 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2.1

orbs:
codacy: codacy/base@2.6.2
codacy_plugins_test: codacy/plugins-test@0.14.5
codacy: codacy/base@5.1.3
codacy_plugins_test: codacy/plugins-test@0.14.6

workflows:
version: 2
Expand All @@ -13,14 +13,12 @@ workflows:
- codacy/sbt:
name: publish_docker_local
cmd: |
docker build -t codacy-rubocop-base .
sbt "set scalafmtUseIvy in ThisBuild := false;
scalafmt::test;
test:scalafmt::test;
sbt:scalafmt::test;
set name := \"$CIRCLE_PROJECT_REPONAME\";
set version in Docker := \"latest\";
docker:publishLocal"
scalafmt::test;
test:scalafmt::test;
sbt:scalafmt::test;
universal:stage"
docker build -t $CIRCLE_PROJECT_REPONAME:latest .
docker save --output docker-image.tar $CIRCLE_PROJECT_REPONAME:latest
persist_to_workspace: true
requires:
Expand Down
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore everything
**

# Allow files and directories
!/Gemfile*
!/target/universal/stage
!/docs

# Ignore unnecessary files inside allowed directories
# This should go after the allowed directories
**/.DS_Store
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src/main/resources/docs/description/* linguist-generated=true
src/main/resources/docs/tool-description.md linguist-generated=true
docs/description/* linguist-generated=true
docs/tool-description.md linguist-generated=true
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/project/target/
/target/
/vendor
/doc/
/src/main/resources/docs/tests/target/
/docs/tests/target/
.idea
.DS_Store
.bundle/
Expand Down
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.12
FROM alpine:3.13 as base

RUN apk add --no-cache ruby ruby-etc ruby-dev ruby-irb ruby-rake ruby-io-console \
ruby-bigdecimal make gcc ruby-json libstdc++ tzdata bash \
Expand All @@ -8,7 +8,16 @@ COPY Gemfile .
COPY Gemfile.lock .

RUN echo 'gem: --no-document' > /etc/gemrc \
&& gem install bundler -v 2.1.4 \
&& gem install bundler -v 2.2.7 \
&& bundle install \
&& gem cleanup \
&& rm -rf /tmp/* /var/cache/apk/*

RUN apk --no-cache add openjdk11
COPY docs /docs
RUN adduser --uid 2004 --disabled-password --gecos "" docker
COPY target/universal/stage/ /workdir/
RUN chmod +x /workdir/bin/codacy-rubocop
USER docker
WORKDIR /workdir
ENTRYPOINT ["bin/codacy-rubocop"]
17 changes: 8 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ end

gem "yard"
gem "rake"
gem "rdoc", "6.3.0"
gem "rdoc"
gem "activesupport"
gem "parser", "3.0.0.0"
gem "parser"
gem "pry"
gem "safe_yaml"
gem "dark_finger"
gem "rubocop-migrations", "0.1.2"
gem "rubocop-github", "0.16.0"
gem "rubocop", "0.82.0"
gem "rubocop-migrations"
gem "rubocop", "1.9.1"
#Rubocop official modules
gem "rubocop-performance", "1.7.1"
gem "rubocop-rails", "2.6.0"
gem "rubocop-rake", "0.5.1"
gem "rubocop-rspec", "1.41.0"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rake"
gem "rubocop-rspec"
62 changes: 31 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.1)
ast (2.4.2)
coderay (1.1.3)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.8)
dark_finger (0.6.1)
rubocop (>= 0.51.0)
i18n (1.8.7)
i18n (1.8.8)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
method_source (1.0.0)
minitest (5.14.3)
parallel (1.20.1)
Expand All @@ -27,36 +26,38 @@ GEM
rainbow (3.0.0)
rake (13.0.3)
rdoc (6.3.0)
regexp_parser (2.0.3)
rexml (3.2.4)
rubocop (0.82.0)
jaro_winkler (~> 1.5.1)
rubocop (1.9.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-github (0.16.0)
rubocop (<= 0.82.0)
rubocop-performance (~> 1.0)
rubocop-rails (~> 2.0)
rubocop-migrations (0.1.2)
rubocop (~> 0.41)
rubocop-performance (1.7.1)
rubocop (>= 0.82.0)
rubocop-rails (2.6.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-migrations (0.1.0)
rubocop (>= 0.42.0)
rubocop-performance (1.9.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.82.0)
rubocop (>= 0.90.0, < 2.0)
rubocop-rake (0.5.1)
rubocop
rubocop-rspec (1.41.0)
rubocop (>= 0.68.1)
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
safe_yaml (1.0.5)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
unicode-display_width (2.0.0)
yard (0.9.26)
zeitwerk (2.4.2)

Expand All @@ -66,19 +67,18 @@ PLATFORMS
DEPENDENCIES
activesupport
dark_finger
parser (= 3.0.0.0)
parser
pry
rake
rdoc (= 6.3.0)
rubocop (= 0.82.0)
rubocop-github (= 0.16.0)
rubocop-migrations (= 0.1.2)
rubocop-performance (= 1.7.1)
rubocop-rails (= 2.6.0)
rubocop-rake (= 0.5.1)
rubocop-rspec (= 1.41.0)
rdoc
rubocop (= 1.9.1)
rubocop-migrations
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
safe_yaml
yard

BUNDLED WITH
2.1.4
2.2.7
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ See the [codacy-engine-scala-seed](/~https://github.com/codacy/codacy-engine-scala
You can create the docker by doing:

```
docker build -t codacy-rubocop-base .
sbt docker:publishLocal
sbt universal:stage
docker build -t codacy-rubocops .
```

The docker is ran with the following command:
Expand All @@ -36,7 +36,7 @@ There are some important details to take into consideration:
+ private val plugins: List[String] = List("rubocop-performance", "rubocop-style")
```

- Add it to src/main/ruby/rubocop_doc/generator.rb
- Add it to doc_generation/codacy/rubocop/generator.rb

```diff
- $plugins = ["rubocop-performance"]
Expand All @@ -57,7 +57,8 @@ You can follow the instructions there to make sure your tool is working as expec

```sh
bundle update
bundle install --path vendor/bundle
bundle config set --local path 'vendor/bundle'
bundle install
./scripts/doc_generate.sh <docs_location>
```

Expand Down
66 changes: 4 additions & 62 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,70 +1,12 @@
import com.typesafe.sbt.packager.docker.Cmd
import sjsonnew.BasicJsonProtocol._
import sjsonnew._
import sjsonnew.support.scalajson.unsafe._

name := "codacy-rubocop"

scalaVersion := "2.13.1"
scalaVersion := "2.13.4"

libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.2.0" withSources (),
"com.codacy" %% "codacy-engine-scala-seed" % "5.0.1",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.8.4",
"org.scala-lang.modules" %% "scala-xml" % "1.3.0",
"com.codacy" %% "codacy-engine-scala-seed" % "5.0.3",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.12.1",
"com.typesafe.play" %% "play-json" % "2.8.1"
)

enablePlugins(JavaAppPackaging)

enablePlugins(DockerPlugin)

lazy val toolVersion = settingKey[String]("The version of the underlying tool retrieved from patterns.json")

toolVersion := {
case class Patterns(name: String, version: String)
implicit val patternsIso: IsoLList[Patterns] =
LList.isoCurried((p: Patterns) => ("name", p.name) :*: ("version", p.version) :*: LNil) {
case (_, n) :*: (_, v) :*: LNil => Patterns(n, v)
}

val jsonFile = (resourceDirectory in Compile).value / "docs" / "patterns.json"
val json = Parser.parseFromFile(jsonFile)
val patterns = json.flatMap(Converter.fromJson[Patterns])
patterns.get.version
}

mappings in Universal ++= (resourceDirectory in Compile).map { resourceDir: File =>
val src = resourceDir / "docs"
val dest = "/docs"

for {
path <- src.allPaths.get if !path.isDirectory
} yield path -> path.toString.replaceFirst(src.toString, dest)
}.value

val dockerUser = "docker"
val dockerGroup = "docker"

daemonUser in Docker := dockerUser
daemonGroup in Docker := dockerGroup

dockerBaseImage := "codacy-rubocop-base"

mappings in Universal += file("scripts/doc_generate.sh") -> "scripts/doc_generate.sh"
mappings in Universal += file("Gemfile") -> "Gemfile"
mappings in Universal += file("doc_generation/codacy/rubocop/generator.rb") -> "doc_generation/codacy/rubocop/generator.rb"
mappings in Universal += file("doc_generation/rubocop_doc/generator.rb") -> "doc_generation/rubocop_doc/generator.rb"

dockerCommands := {
dockerCommands.value.flatMap {
case cmd @ (Cmd("ADD", _)) =>
Seq(
Cmd("RUN", s"adduser -u 2004 -D $dockerUser"),
cmd,
Cmd("RUN", "sh scripts/doc_generate.sh $PWD"),
Cmd("RUN", "apk del ruby-dev make gcc"),
Cmd("RUN", "mv /opt/docker/docs /docs")
)
case other => Seq(other)
}
}
8 changes: 4 additions & 4 deletions doc_generation/codacy/rubocop/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.info_url(cop_data)
"http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/#{cop_data[:name]}"
end

def self.run(baseDir = "src/main/resources", file_path = "rubocop-doc.yml")
def self.run(baseDir = "", file_path = "rubocop-doc.yml")
@baseDir = baseDir
cops_data = YAML.load_file(file_path)
cops_data.each do |cop_data|
Expand Down Expand Up @@ -70,7 +70,7 @@ def self.parameters(cop_data)
end
end

def self.run(baseDir = "src/main/resources", file_path = "rubocop-doc.yml")
def self.run(baseDir = "", file_path = "rubocop-doc.yml")
@baseDir = baseDir
cops_data = YAML.load_file(file_path)
descriptions = cops_data.map do |cop_data|
Expand Down Expand Up @@ -145,7 +145,7 @@ def self.parameters(cop_data)
end
end

def self.run(default_patterns, baseDir = "src/main/resources", file_path = "rubocop-doc.yml")
def self.run(default_patterns, baseDir = "", file_path = "rubocop-doc.yml")
@baseDir=baseDir
cops_data = YAML.load_file(file_path)
patterns = cops_data.map do |cop_data|
Expand All @@ -171,7 +171,7 @@ def self.run(default_patterns, baseDir = "src/main/resources", file_path = "rubo
end
end

baseDir="src/main/resources"
baseDir=""
if ARGV.length == 1
baseDir=ARGV[0]
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8e6aee

Please sign in to comment.