diff --git a/.lintstagedrc.js b/.lintstagedrc.js index 4b57de337..d5bcfbd35 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,49 +1,52 @@ const { CLIEngine } = require('eslint'); const { getClangPaths } = require('./scripts/get_clang_paths'); const cli = new CLIEngine({}); module.exports = { '*.{js,mjs,cjs}': function eslint(files) { // This logic is likely broken and needs to be updated. see ENG-1011 return ( 'eslint --cache --fix --max-warnings=0 ' + files.filter(file => !cli.isPathIgnored(file)).join(' ') ); }, '*.{css,html,md,json}': function prettier(files) { return 'prettier --write ' + files.join(' '); }, 'lib/**/*.js': function libFlow(files) { return 'yarn workspace lib flow --quiet'; }, '{web,lib}/**/*.js': function webFlow(files) { return 'yarn workspace web flow --quiet'; }, '{native,lib}/**/*.js': function nativeFlow(files) { return 'yarn workspace native flow --quiet'; }, '{keyserver,web,lib}/**/*.js': function keyServerFlow(files) { return 'yarn workspace keyserver flow --quiet'; }, '{landing,lib}/**/*.js': function landingFlow(files) { return 'yarn workspace landing flow --quiet'; }, '{native,services}/**/*.{h,cpp,java,mm}': function clangFormat(files) { files = files.filter(path => { if (path.indexOf('generated') !== -1) { return false; } for (const allowedPath of getClangPaths()) { if (path.indexOf(allowedPath) !== -1) { return true; } } return false; }); return 'clang-format -i ' + files.join(' '); }, 'services/commtest/**/*.rs': function rustFormat(files) { return 'yarn rust-pre-commit'; }, + 'services/terraform/*.tf': function checkTerraform(files) { + return 'yarn terraform-pre-commit'; + }, }; diff --git a/package.json b/package.json index 60cd9f12f..0a5e609e1 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,39 @@ { "private": true, "license": "BSD-3-Clause", "workspaces": [ "lib", "web", "native", "keyserver", "landing" ], "scripts": { "clean": "yarn workspace lib clean && yarn workspace web clean && yarn workspace native clean && yarn workspace keyserver clean && yarn workspace landing clean && rm -rf node_modules/", "cleaninstall": "yarn clean && yarn", "eslint": "eslint .", "eslint:fix": "eslint --fix .", "clang-format-all": "eval `node scripts/get_clang_paths_cli.js` | xargs clang-format -i", "rust-pre-commit": "./scripts/rust_pre_commit.sh", + "terraform-pre-commit": "./scripts/terraform_pre_commit.sh", "prepare": "husky install" }, "devDependencies": { "babel-eslint": "^10.1.0", "clang-format": "^1.8.0", "core-js": "^3.6.5", "eslint": "^7.22.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-flowtype": "^5.4.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jest": "^24.2.2", "eslint-plugin-monorepo": "^0.3.2", "eslint-plugin-prettier": "^3.3.1", "eslint-plugin-react": "^7.22.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-native": "^3.10.0", "husky": "^7.0.0", "lint-staged": "^12.1.4", "prettier": "^2.1.2" } } diff --git a/scripts/terraform_pre_commit.sh b/scripts/terraform_pre_commit.sh new file mode 100755 index 000000000..ccb180182 --- /dev/null +++ b/scripts/terraform_pre_commit.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +cd services/terraform +echo "formatting services/terraform..." +terraform fmt -check +echo "validating services/terraform..." +terraform validate +echo "done formatting and validating"