Skip to content

skylint

A Starlark linter that wraps buildtools warnings with a modern CLI interface, auto-fix support, and multiple output formats.

Terminal window
go install github.com/albertocavalcante/sky/cmd/skylint@latest
Terminal window
# Lint a single file
skylint BUILD.bazel
# Lint all files recursively
skylint ./...
# Enable all rules
skylint --enable=all .
# Auto-fix issues
skylint --fix .
# Preview fixes without applying
skylint --fix --diff .
# Output as JSON (for CI integration)
skylint --format=json .
# GitHub Actions format
skylint --format=github .
FormatDescription
textHuman-readable output (default)
compactSingle line per issue
jsonMachine-readable JSON
githubGitHub Actions annotations

skylint wraps all buildtools warnings. Use skylint --list-rules to see the exact categorization.

CategoryDescription
correctnessLogic errors and bugs
styleCode style and formatting
importsLoad statement issues
unusedUnused code detection
documentationDocstring requirements
deprecationDeprecated API usage
bazel-apiBazel-specific API issues
native-rulesNative rule migration
compatibilityPython/Starlark compatibility
control-flowControl flow issues
RuleDescription
attr-cfgChecks for invalid cfg attribute
attr-non-emptyChecks for non-empty attribute requirements
attr-output-defaultChecks for output attributes with defaults
build-args-kwargsChecks for **kwargs in build rules
constant-globChecks for constant glob patterns
duplicated-nameChecks for duplicate variable names
keyword-position-argsChecks for positional args after keywords
positional-argsChecks for too many positional args
redefined-variableChecks for variable redefinition
return-valueChecks for return value issues
rule-impl-returnChecks rule implementation return value
uninitializedChecks for uninitialized variables
unnamed-macroChecks for unnamed macro definitions
RuleDescription
confusing-nameChecks for confusing variable names
name-conventionsChecks naming conventions
package-on-topChecks that package() is at top
printChecks for print statements
unsorted-dict-itemsChecks for unsorted dictionary items
RuleDescription
return-inside-loopChecks for return statements inside loops
RuleDescription
loadChecks for unused load statements
load-on-topChecks that loads are at top of file
same-origin-loadChecks for same-origin load statements
RuleDescription
no-effectChecks for statements with no effect
unreachableChecks for unreachable code
unused-variableChecks for unused variables
RuleDescription
function-docstringChecks for missing function docstrings
function-docstring-argsChecks function docstring documents args
function-docstring-headerChecks function docstring header format
function-docstring-returnChecks function docstring documents return
module-docstringChecks for missing module docstrings
RuleDescription
attr-licenseChecks for deprecated licenses attribute
attr-single-fileChecks for single_file attribute usage
bzl-visibilityChecks for deprecated bzl_visibility
ctx-actionsChecks for deprecated ctx.action
ctx-argsChecks for deprecated ctx.outputs and ctx.files
deprecated-functionChecks for deprecated function usage
depset-iterationChecks for iteration over depset
depset-unionChecks for deprecated depset union
dict-concatenationChecks for dict concatenation with +
filetypeChecks for deprecated FileType usage
git-repositoryChecks for deprecated git_repository
http-archiveChecks for deprecated http_archive
output-groupChecks for deprecated OutputGroupInfo
package-nameChecks for deprecated PACKAGE_NAME
repository-nameChecks for deprecated REPOSITORY_NAME
RuleDescription
overly-nested-depsetChecks for deeply nested depsets
provider-paramsChecks provider parameter usage
RuleDescription
native-androidChecks for native android_* rules
native-buildChecks for native.existing_rules usage
native-ccChecks for native cc_* rules
native-javaChecks for native java_* rules
native-packageChecks for native.package usage
native-protoChecks for native proto_* rules
native-pyChecks for native py_* rules
RuleDescription
integer-divisionChecks for integer division compatibility
string-iterationChecks for string iteration compatibility

Create a .skylint.json file in your project root:

{
"enable": ["all"],
"disable": ["print", "module-docstring"],
"warnings_as_errors": false
}
OptionDescription
enableRules to enable (supports all and category names)
disableRules to disable (supports glob patterns like native-*)
warnings_as_errorsTreat warnings as errors

Many rules support automatic fixing:

Terminal window
# Fix all fixable issues
skylint --fix .
# Preview fixes as diff
skylint --fix --diff .

Get detailed information about a specific rule:

Terminal window
skylint --explain=load

Output:

Rule: load
Category: imports
Severity: warning
Auto-fix: true
Description:
Checks for unused load statements
Documentation:
https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#load

Suppress warnings with comments:

# Suppress on the current line (comment-only line)
# skylint: disable=print
print("Debug output")
# Suppress on the next line
# skylint: disable-next-line=unused-variable
unused = compute_value()
# Inline suppression (same line as code)
print("Debug") # skylint: disable=print

Multiple rules can be suppressed with commas:

# skylint: disable=print,unused-variable
- name: Lint Starlark
run: skylint --format=github ./...
repos:
- repo: local
hooks:
- id: skylint
name: skylint
entry: skylint
language: system
files: \.(bzl|bazel|star)$
CodeMeaning
0Success (no issues)
1Error (lint errors or tool failure)
2Warning (warnings found, no errors)

Use --warnings-as-errors to treat warnings as errors (exit code 1).