Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add editorconfig #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://EditorConfig.org

root = true

[*]
indent_size = 4
indent_style = space
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For .go

Indentation
We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.

https://go.dev/doc/effective_go#formatting

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not leave .go files out of editorconfig and do something like
openshift/oadp-operator#1337

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not understand the linked PR

but yes, go files and Makefile both accept tabs and spaces (go example of spaces: the headers copyright), so added them to list of indent_style=unset. go fmt (run by golangci-lint) will take care of this for us in go files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tab character is a very important part of the syntax of Makefiles.

So Makefile should not be indented using spaces. Yes unset sounds good.

Spaces can exists in go and makefile but not as an indent method for non-comments.

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.go,go.mod,Makefile}]
indent_style = unset

[{*.{yaml,yml},PROJECT}]
indent_size = 2

[{*.md,LICENSE}]
indent_size = unset
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ jobs:
- name: Check if 'make manifests' was run
run: make check-manifests

# TODO editorconfig
- name: Check all files format
run: make ec
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,23 @@ endef

##@ oadp-nac specifics

EC ?= $(LOCALBIN)/ec-$(EC_VERSION)
EC_VERSION ?= 2.8.0

.PHONY: editorconfig
editorconfig: $(LOCALBIN) ## Download editorconfig locally if necessary.
@[ -f $(EC) ] || { \
set -e ;\
ec_binary=ec-$(shell go env GOOS)-$(shell go env GOARCH) ;\
ec_tar=$(LOCALBIN)/$${ec_binary}.tar.gz ;\
curl -sSLo $${ec_tar} https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$(EC_VERSION)/$${ec_binary}.tar.gz ;\
tar xzf $${ec_tar} ;\
rm -rf $${ec_tar} ;\
mv $(LOCALBIN)/$${ec_binary} $(EC) ;\
}

.PHONY: ci
ci: simulation-test lint docker-build hadolint check-generate check-manifests ## Run all checks run by the project continuous integration (CI) locally.
ci: simulation-test lint docker-build hadolint check-generate check-manifests ec ## Run all checks run by the project continuous integration (CI) locally.
kaovilai marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: simulation-test
simulation-test: envtest ## Run unit and integration tests.
Expand All @@ -222,3 +237,7 @@ check-generate: generate ## Check if 'make generate' was run.
.PHONY: check-manifests
check-manifests: manifests ## Check if 'make manifests' was run.
test -z "$(shell git status --short)" || (echo "run 'make manifests' to generate code" && exit 1)

.PHONY: ec
ec: editorconfig ## Run file formatter checks against all project's files.
$(EC)
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ metadata:
name: cluster
spec:
identityProviders:
- name: oadp_nac_test_provider
mappingMethod: claim
- name: oadp_nac_test_provider
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
name: htpass-secret
EOF
```
**Apply the OAuth file to the cluster:**
Expand All @@ -60,7 +60,7 @@ $ oc apply -f config/rbac/nonadminbackup_editor_role.yaml

**Create Role Binding for our test user within nac-testing namespace:**
**NOTE:** There could be also a ClusterRoleBinding for the nacuser or one of the groups
to which nacuser belongs to easy administrative tasks and allow use of NAC for wider audience. Please see next paragraph.
to which nacuser belongs to easy administrative tasks and allow use of NAC for wider audience. Please see next paragraph.
```sh
$ cat > nacuser-rolebinding.yaml <<EOF
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -114,8 +114,8 @@ export IMG_REGISTRY="quay.io/<USER>/oadp-nac"
make docker-build docker-push IMG="${IMG_REGISTRY}:${NAC_REV}" CONTAINER_TOOL=podman
```

**NOTE:** This image ought to be published in the personal registry you specified.
And it is required to have access to pull the image from the working environment.
**NOTE:** This image ought to be published in the personal registry you specified.
And it is required to have access to pull the image from the working environment.
Make sure you have the proper permission to the registry if the above commands don’t work.

**Install the CRDs into the cluster:**
Expand Down Expand Up @@ -155,7 +155,7 @@ replicaset.apps/oadp-nac-controller-manager-74bbf4577b 1 1 1

```

> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
privileges or be logged in as admin.

**Create instances of your solution**
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
*/