{"id":1069,"date":"2021-01-10T15:37:53","date_gmt":"2021-01-10T06:37:53","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/?p=1069"},"modified":"2021-01-12T17:29:00","modified_gmt":"2021-01-12T08:29:00","slug":"golangci-lint-circleci","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2021\/01\/10\/golangci-lint-circleci\/","title":{"rendered":"GolangCI-Lint\u3068CircleCI\u3092\u5229\u7528\u3057\u3066\u9759\u7684\u89e3\u6790\u30c1\u30a7\u30c3\u30af\u3092\u81ea\u52d5\u5316\u3059\u308b"},"content":{"rendered":"
\u8179\u7b4b\u30ed\u30fc\u30e9\u30fc\u3067\u5f90\u3005\u306b\u7acb\u3061\u30b3\u30ed\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002\u3084\u3063\u3055\u3093\u3067\u3059\u3002
\nGolangCI-Lint\u3068CircleCI\u3067\u9759\u7684\u89e3\u6790\u30c1\u30a7\u30c3\u30af\u3092\u81ea\u52d5\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
Linter\u3068\u306f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u9759\u7684\u89e3\u6790\u3092\u884c\u3046\u30c4\u30fc\u30eb\u3067\u3059\u3002\u4e8b\u524d\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u306e\u691c\u77e5\u3084\u3001\u3075\u3055\u308f\u3057\u304f\u306a\u3044\u69cb\u6587\u306a\u3069\u3092\u691c\u77e5\u3059\u308b\u305f\u3081\u306b\u5229\u7528\u3057\u307e\u3059\u3002\u8a00\u8a9e\u6bce\u306b\u5b58\u5728\u3057\u3066\u304a\u308a\u3001\u4f8b\u3048\u3070Java\u3067\u3042\u308c\u3070Checkstyle\u3001Ruby\u3067\u306fRuboCop\u304c\u6709\u540d\u3067\u3059\u306d\u3002<\/p>\n
\nGo\u8a00\u8a9e\u306f\u8907\u6570\u306eLinter\u304c\u4e71\u7acb\u3057\u3066\u304a\u308a\u3001\u3069\u306eLinter\u3092\u4f7f\u3046\u3079\u304d\u304b\u60a9\u3080\u3053\u3068\u3082\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002GolangCI-Lint\u306fLinter\u3092\u4e00\u5143\u7ba1\u7406\u3057\u9ad8\u901f\u306bLinter\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u30c4\u30fc\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n
GolangCI-Lint\u3092\u4f7f\u3046\u3053\u3068\u3067\u4ee5\u4e0b\u306e\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
GolangCI-Lint\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u3001\u500b\u5225\u306eLinter\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0d\u8981\u3067\u3059\u306e\u3067\u3001\u4e00\u62ec\u3067\u4e3b\u8981\u306aLiner\u3092\u5c0e\u5165\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5229\u7528\u3057\u305f\u3044Linter\u306e\u6570\u304c\u5897\u3048\u308b\u307b\u3069\u306b\u3001\u958b\u767a\u8005\u306e\u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u304c\u7169\u308f\u3057\u304f\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u4e00\u62ec\u3067Linter\u3092\u5c0e\u5165\u3067\u304d\u308b\u3053\u3068\u306f\u5927\u5909\u4fbf\u5229\u3067\u3059\u3002<\/p>\n
\u7d99\u7d9a\u7684\u30a4\u30f3\u30c6\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\uff08CI\uff09\u306b\u304a\u3044\u3066Linter\u3092\u5b9f\u884c\u3057\u3001\u9759\u7684\u89e3\u6790\u7d50\u679c\u306b\u554f\u984c\u304c\u3042\u308b\u5834\u5408\u306f\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3092\u5b9f\u884c\u305b\u305a\u306b\u30a8\u30e9\u30fc\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u958b\u767a\u8005\u306f\u5fc5\u7136\u7684\u306b\u9759\u7684\u89e3\u6790\u7d50\u679c\u306e\u4fee\u6b63\u3092\u8feb\u3089\u308c\u54c1\u8cea\u306e\u9ad8\u3044\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n
GolangCI-Lint\u306f\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u304a\u308a\u3001Git\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u30eb\u30fc\u30c8\u914d\u4e0b\u306b\u914d\u7f6e\u3059\u308b\u3053\u3068\u3067\u3001\u30ea\u30dd\u30b8\u30c8\u30ea\u6bce\u306bLinter\u306e\u30eb\u30fc\u30eb\u3092\u660e\u78ba\u306b\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u3069\u306eLinter\u3092\u5229\u7528\u3059\u308b\u304b\u306f\u3082\u3061\u308d\u3093\u306e\u3053\u3068\u3001\u5404Linter\u306e\u8a73\u7d30\u8a2d\u5b9a\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n
GoLangCI-Lint\u306f\u975e\u5e38\u306b\u9ad8\u901f\u3067\u3042\u308b\u3053\u3068\u3092\u30a2\u30d4\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u3002Linter\u3092\u4e26\u5217\u306b\u5b9f\u884c\u3057\u3001Go\u30d3\u30eb\u30c9\u30ad\u30e3\u30c3\u30b7\u30e5\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u89e3\u6790\u7d50\u679c\u3092\u518d\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n
Go\u8a00\u8a9e\u306fLinter\u304c\u4e71\u7acb\u72b6\u614b\u3067\u3057\u3066\u300140\u3092\u8d85\u3048\u308bLinter\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002\u4e3b\u8981\u306aLinter\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
gofmt\u306fGo\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\uff08\u6574\u5f62\uff09\u3059\u308b\u30c4\u30fc\u30eb\u3067\u3059\u3002gofmt\u306f\u81ea\u52d5\u6574\u5f62\u304ct\u3068\u3066\u3082\u4fbf\u5229\u3067\u3057\u3066\u3001Visual Studio Code\u306a\u3069\u306eIDE\u3067\u30d5\u30a1\u30a4\u30eb\u66f4\u65b0\u6642\u306b\u81ea\u52d5\u6574\u5f62\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n
golint\u306f\u30b9\u30bf\u30a4\u30eb\u30df\u30b9\u3092\u51fa\u529b\u3057\u307e\u3059\u3002golint \u306f\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30b9\u30bf\u30a4\u30eb\u3092\u91cd\u8996\u3057\u3066\u304a\u308a\u3001\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u306eGo\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u53d7\u3051\u5165\u308c\u3089\u308c\u3066\u3044\u308b\u30b9\u30bf\u30a4\u30eb\u3068\u4e00\u81f4\u3055\u305b\u3088\u3046\u3068\u3057\u3066\u3044\u307e\u3059\u3002golint\u306b\u5f93\u3046\u3060\u3051\u3067\u30bb\u30f3\u30b9\u306e\u3042\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n
govet \u306f Go \u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u691c\u67fb\u3057\u3066\u3001\u5f15\u6570\u304c\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u6587\u5b57\u5217\u3068\u4e00\u81f4\u3057\u306a\u3044 Printf \u547c\u3073\u51fa\u3057\u306a\u3069\u306e\u7591\u308f\u3057\u3044\u69cb\u9020\u3092\u5831\u544a\u3057\u307e\u3059\u3002Vet \u306f\u3001\u3059\u3079\u3066\u306e\u30ec\u30dd\u30fc\u30c8\u304c\u672c\u7269\u306e\u554f\u984c\u3067\u3042\u308b\u3053\u3068\u3092\u4fdd\u8a3c\u3057\u306a\u3044\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\u3092\u4f7f\u7528\u3057\u307e\u3059\u304c\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u3067\u306f\u691c\u51fa\u3067\u304d\u306a\u3044\u30a8\u30e9\u30fc\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
\u305d\u308c\u3067\u306f\u3001GolangCI-Lint\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u3066\u3044\u304d\u307e\u3059\u3002
\n\u4eca\u56de\u306f\u30ed\u30fc\u30ab\u30eb\u5b9f\u884c\u306fMac\u3092\u3001CircleCI\u306fLinux\u74b0\u5883\u3092\u524d\u63d0\u3068\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n
homebrew\u3092\u4f7f\u3044\u7c21\u5358\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n
brew install golangci-lint\nbrew upgrade golangci-lint<\/code><\/pre>\nGolangCI-Lint\u3092\u5b9f\u884c\u3059\u308b<\/h2>\n
\u65e9\u901f\u3001GolangCI-Lint\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002
\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n
golangci-lint run<\/code><\/pre>\n\u5b9f\u884c\u3059\u308b\u3068\u3001Linter\u306e\u7d50\u679c\u304c\u6a19\u6e96\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u3002\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u5229\u7528\u3057\u306a\u3044\u5834\u5408\u3001GolangCI-Lint\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308bLinter\u3092\u5229\u7528\u3057\u307e\u3059\u3002\u5b9f\u884c\u7d50\u679c\u306e\u4f8b\u3067\u306f\u3001unused\u3067\u5229\u7528\u3057\u3066\u3044\u306a\u3044\u30e1\u30bd\u30c3\u30c9\u304c\u691c\u51fa\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n
domain\/inquiry.go:173:34: func `ConsultationContentCode.getText` is unused (unused)<\/code><\/pre>\n\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067Linter\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n
\u4eca\u56de\u306fGit\u30ea\u30dd\u30b8\u30c8\u30ea\u3067Linter\u3092\u6307\u5b9a\u3057\u305f\u3044\u305f\u3081\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092Git\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u30eb\u30fc\u30c8\u914d\u4e0b\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\u30d5\u30a1\u30a4\u30eb\u540d\u306f .golangci.yml<\/code> \u3068\u3057\u307e\u3057\u305f\u3002\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5bb9\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\nlinters:\n enable:\n - errcheck\n - gosimple\n - govet\n - staticcheck\n - unused\n - gofmt\n - golint\n disable-all: true<\/code><\/pre>\n\u3082\u3046\u4e00\u5ea6Linter\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n
\u5148\u7a0b\u3068\u540c\u3058\u30b3\u30de\u30f3\u30c9\u3067\u3001\u3082\u3046\u4e00\u5ea6Linter\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002
\n\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002\u65b0\u305f\u306b golint<\/code> \u306b\u3088\u308b\u691c\u51fa\u7d50\u679c\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\nusecase\/inquiry_interactor.go:126:64: func parameter `sourceIp` should be `sourceIP` (golint)\ndomain\/inquiry.go:173:34: func `ConsultationContentCode.getText` is unused (unused)\n<\/code><\/pre>\n\u3069\u306eLinter\u3067\u691c\u51fa\u3055\u308c\u305f\u304b\u3069\u3046\u304b\u306f\u3001\u51fa\u529b\u306e\u6700\u5f8c\u306e\u304b\u3063\u3053\u306e\u7b87\u6240\u3067\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n
Docker Container\u3067GolangCI-Lint\u3092\u5b9f\u884c\u3059\u308b<\/h2>\n
Docker\u30b3\u30f3\u30c6\u30ca\u74b0\u5883\u4e0b\u3067GolangCI-Lint\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u3001\u958b\u767a\u8005\u306e\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u74b0\u5883\u306b\u4f9d\u5b58\u305b\u305a\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n
Dockerfile<\/h3>\n
GolangCI-Lint\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306fwget\u3068sh\u30b3\u30de\u30f3\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
FROM golang:1.15.6-alpine\n\n# install packages\nRUN apk update && apk add --no-cache bash make curl git gcc libc-dev openssl\n\n# Install golangci-lint & test library\nRUN wget -O- -nv https:\/\/raw.githubusercontent.com\/golangci\/golangci-lint\/master\/install.sh | sh -s v1.35.0\n\nWORKDIR \/go\/src\/app\nCOPY . \/go\/src\/app\/\n\n# go mod download\nRUN go mod download<\/code><\/pre>\nDocke\u30b3\u30f3\u30c6\u30ca\u3067GolangCI-Lint\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n
\u3053\u3061\u3089\u306fDocker\u306e\u304a\u4f5c\u6cd5\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n
docker run -it \u3010\u30a4\u30e1\u30fc\u30b8ID\u3011 golangci-lint run<\/code><\/pre>\nCircle CI\u3067\u5b9f\u884c\u3059\u308b<\/h2>\n
Dockerfile\u307e\u3067\u7528\u610f\u304c\u3067\u304d\u307e\u3057\u305f\u3089\u3001CircleCI\u3067\u81ea\u52d5\u5316\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u3059\u3002\u4eca\u56de\u306fCircleCI\u3067Docker\u3092\u8d77\u52d5\u3059\u308bDocker in Docker\u5229\u7528\u3057\u3066\u307f\u307e\u3059\u3002\u5148\u7a0b\u306eDockerfile\u3092docker-compose\u30d5\u30a1\u30a4\u30eb\u3067\u8d77\u52d5\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n
\u3053\u308c\u3092\u3001make\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306bMakefile\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n
ci-lint:\n docker-compose -f docker-compose-ci.yml run build golangci-lint run<\/code><\/pre>\nCircleCI\u3067\u306fmake\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b .circleci\/config.yml<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306b\u8a18\u8ff0\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\njobs:\n build:\n working_directory: \/go\/src\/app\n <<: *defaults\n steps:\n - run:\n name: Install curl\n command: sudo apt-get update && sudo apt-get install -y curl vim-tiny make git\n - run:\n name: Install Docker Compose\n command: |\n sudo curl -L https:\/\/github.com\/docker\/compose\/releases\/download\/1.19.0\/docker-compose-`uname -s`-`uname -m` > ~\/docker-compose\n sudo chmod +x ~\/docker-compose\n sudo mv ~\/docker-compose \/usr\/local\/bin\/docker-compose\n - checkout\n - setup_remote_docker\n - run:\n name: run golangci-lint\n command: make ci-lint<\/code><\/pre>\nGoLand\u306eGolangCI-Lint\u30d7\u30e9\u30b0\u30a4\u30f3<\/h2>\n
\n\u7d71\u5408\u958b\u767a\u74b0\u5883\u306eGoLand\u3067\u306fGolangCI-Lint\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u304c\u63d0\u4f9b\u3055\u308c\u3066\u304a\u308a\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u5165\u529b\u88dc\u5b8c\u3084\u3001\u30a8\u30c7\u30a3\u30bf\u4e0a\u3067\u306e\u30cf\u30a4\u30e9\u30a4\u30c8\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n