Skip to content

Commit

Permalink
feat: install linting (#2)
Browse files Browse the repository at this point in the history
* feat: install linting

* chore: add missing files
  • Loading branch information
alexeagle authored May 11, 2024
1 parent 192bae4 commit 20f84ad
Show file tree
Hide file tree
Showing 14 changed files with 1,118 additions and 35 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ jobs:
cd scaffold_test*
git init
echo "::set-output name=dir::$PWD"
- name: Test
- run: bazel test ...
working-directory: "${{ steps.scaffold.outputs.dir }}"
run: bazel test ...
- name: Format

- run: bazel run format
working-directory: "${{ steps.scaffold.outputs.dir }}"
if: "${{ matrix.preset != 'minimal' }}"
run: bazel run format

- run: bazel lint ...
working-directory: "${{ steps.scaffold.outputs.dir }}"
32 changes: 19 additions & 13 deletions scaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
messages:
pre: |
# Aspect starter
# Welcome to Aspect
Generate boilerplate code for a new Bazel project using Aspect CLI
Generate boilerplate code for a new Bazel project using Aspect CLI and Aspect Workflows.
post: |
# Get Started
1. Read the developer guide in {{ .ProjectSnake }}/README.bazel.md
2. Try out some commands, such as:
```sh
cd {{ .ProjectSnake }}
{{- if .Scaffold.fmt }}
{{- if .Scaffold.lint }}
aspect run format
{{- end }}
aspect test ...
```
questions:
- name: fmt
- name: lint
prompt:
confirm: "Setup formatter?"
confirm: "Setup format and linting?"
- name: langs
prompt:
multi: true
Expand All @@ -27,34 +31,36 @@ questions:
- Python

features:
- value: "{{ .Scaffold.fmt }}"
- value: "{{ .Scaffold.lint }}"
globs:
- "**/tools/format/*"
- "*/tools/format/*"
- "*/tools/lint/*"
- value: "{{ .Computed.javascript }}"
globs:
- "*/package.json"
- "*/pnpm-*.yaml"
- "*/.eslintrc*"
- "*/.npmrc"
- "**/packages/**"
- value: "{{ .Computed.python }}"
globs:
- "*/requirements.txt"
- "*/requirements_lock.txt"
- "*/requirements*.txt"
- "*/pyproject.toml"

computed:
javascript: "{{ has \"JavaScript & TypeScript\" .Scaffold.langs }}"
python: "{{ has \"Python\" .Scaffold.langs }}"

presets:
kitchen-sink:
fmt: true
lint: true
langs: ['JavaScript & TypeScript', 'Python']
js:
fmt: true
lint: true
langs: ['JavaScript & TypeScript']
py:
fmt: true
lint: true
langs: ['Python']
minimal:
fmt: false
lint: false
langs: []
17 changes: 12 additions & 5 deletions {{ .ProjectSnake }}/.aspect/cli/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
configure:
languages:
{{- range .Scaffold.langs}}
{{- if eq . "JavaScript"}}
javascript: true
{{- end}}
languages:
{{- if eq .Computed.javascript "true" }}
javascript: true
{{- end}}

lint:
aspects:
{{- if eq .Computed.javascript "true" }}
- //tools/lint:linters.bzl%eslint
{{- end }}
{{- if eq .Computed.python "true" }}
- //tools/lint:linters.bzl%ruff
{{- end }}
7 changes: 7 additions & 0 deletions {{ .ProjectSnake }}/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint/eslint-plugin"],
root: true,
};
32 changes: 27 additions & 5 deletions {{ .ProjectSnake }}/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
"Targets in the workspace root"
{{- if .Scaffold.Computed.javascript }}
{{- if eq .Computed.javascript "true" }}
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")
{{ end }}
{{- if .Scaffold.Computed.python }}
{{- if eq .Computed.python "true" }}
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
{{ end}}

{{- if .Scaffold.fmt }}
{{- if .Scaffold.lint }}
alias(
name = "format",
actual = "//tools/format",
)

exports_files(
[
{{- if eq .Computed.python "true" }}
"pyproject.toml",
{{- end }}
],
visibility = ["//visibility:public"],
)
{{- end }}

{{- if .Scaffold.Computed.javascript }}
{{- if eq .Computed.javascript "true" }}
npm_link_all_packages(name = "node_modules")

{{- if .Scaffold.lint }}
js_library(
name = "eslintrc",
srcs = [".eslintrc.cjs"],
deps = [
":node_modules/@typescript-eslint/eslint-plugin",
":node_modules/@typescript-eslint/parser",
],
visibility = ["//:__subpackages__"],
)
{{- end }}
{{- end }}

{{- if .Scaffold.Computed.python }}
{{- if eq .Computed.python "true" }}
compile_pip_requirements(
name = "requirements",
requirements_in = "requirements.txt",
Expand Down
14 changes: 10 additions & 4 deletions {{ .ProjectSnake }}/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "aspect_rules_lint", version = "0.20.0")
bazel_dep(name = "rules_multitool", version = "0.7.1")
{{- if .Scaffold.Computed.javascript }}
{{- if eq .Computed.javascript "true" }}
bazel_dep(name = "aspect_rules_js", version = "1.42.0")
bazel_dep(name = "aspect_rules_ts", version = "2.3.0")
{{- end}}
{{- if .Scaffold.Computed.python }}
{{- if eq .Computed.python "true" }}
bazel_dep(name = "rules_python", version = "0.31.0")
bazel_dep(name = "aspect_rules_py", version = "0.7.3")
{{- end }}

git_override(
module_name = "aspect_rules_lint",
remote = "https://github.com/aspect-build/rules_lint.git",
commit = "53ab16800ac312c612f174bb8fc6bc335d9defd9",
)

multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
multitool.hub(lockfile = "//tools:tools.lock.json")
use_repo(multitool, "multitool")

{{- if .Scaffold.Computed.javascript}}
{{- if eq .Computed.javascript "true" }}
pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
# Allows developers to run the same pnpm version that Bazel manages
use_repo(pnpm, "pnpm")
Expand All @@ -37,7 +43,7 @@ rules_ts_ext.deps()
use_repo(rules_ts_ext, "npm_typescript")
{{- end}}

{{- if .Scaffold.Computed.python }}
{{- if eq .Computed.python "true" }}
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
Expand Down
4 changes: 2 additions & 2 deletions {{ .ProjectSnake }}/README.bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This repository uses [Aspect Workflows](https://aspect.build) to provide an excellent Bazel developer experience.

## Formatting
## Formatting code

- Run `aspect run format` to re-format all files locally.
- Run `aspect run format path/to/file` to re-format a single file.
Expand All @@ -19,7 +19,7 @@ For developers to be able to run a CLI tool without needing manual installation:

See https://blog.aspect.build/run-tools-installed-by-bazel for details.

{{ if .Scaffold.Computed.javascript }}
{{- if eq .Computed.javascript "true" }}
## Working with npm packages

To install a `node_modules` tree locally for the editor or other tooling outside of Bazel:
Expand Down
6 changes: 6 additions & 0 deletions {{ .ProjectSnake }}/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
#
# This file is a marker indicating the root of a Bazel workspace.
# See MODULE.bazel for dependency information.

{{- if eq .Computed.python "true" }}
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")

fetch_ruff()
{{- end }}
9 changes: 8 additions & 1 deletion {{ .ProjectSnake }}/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"name": "{{ .Project }}",
"private": true
"private": true,
"devDependencies": {
"eslint": "^8",
"@typescript-eslint/parser": "*",
"@typescript-eslint/eslint-plugin": "*",
"typescript": "5.4.5",
"prettier": "*"
}
}
Loading

0 comments on commit 20f84ad

Please sign in to comment.