# Copyright 2021-2022, 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.

#+PROPERTY: header-args :mkdirp yes :main no

* Test data for ~bazel-mode-flymake~

#+BEGIN_SRC bazel-module :tangle MODULE.bazel
# empty
#+END_SRC

#+NAME: starlark
#+BEGIN_SRC bazel-starlark :tangle buildifier.bzl
def foo(bar):
    """ """
    a = 1 / 2
#+END_SRC

To make the Flymake test hermetic, we generate Buildifier output statically and
tangle the output when running the test.  Execute this code block to regenerate
the Buildifier output:

#+BEGIN_SRC sh :noweb yes :results output scalar :wrap "src js :tangle buildifier.json"
buildifier -mode=check -lint=warn -format=json -v -path=buildifier.bzl <<'EOF'
<<starlark>>
EOF
#+END_SRC

#+RESULTS:
#+BEGIN_SRC js :tangle buildifier.json
{
    "success": false,
    "files": [
        {
            "filename": "buildifier.bzl",
            "formatted": true,
            "valid": true,
            "warnings": [
                {
                    "start": {
                        "line": 1,
                        "column": 1
                    },
                    "end": {
                        "line": 1,
                        "column": 2
                    },
                    "category": "module-docstring",
                    "actionable": true,
                    "message": "The file has no module docstring.\nA module docstring is a string literal (not a comment) which should be the first statement of a file (it may follow comment lines).",
                    "url": "https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#module-docstring"
                },
                {
                    "start": {
                        "line": 2,
                        "column": 5
                    },
                    "end": {
                        "line": 2,
                        "column": 12
                    },
                    "category": "function-docstring-header",
                    "actionable": true,
                    "message": "The docstring for the function \"foo\" should start with a one-line summary.",
                    "url": "https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#function-docstring-header"
                },
                {
                    "start": {
                        "line": 3,
                        "column": 9
                    },
                    "end": {
                        "line": 3,
                        "column": 14
                    },
                    "category": "integer-division",
                    "actionable": true,
                    "message": "The \"/\" operator for integer division is deprecated in favor of \"//\".",
                    "url": "https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#integer-division"
                }
            ]
        }
    ]
}
#+END_SRC

We also provide a “fake” Buildifier binary that only emits our canned output.
It waits for the file =signal= to exist; you can use this to simulate a “slow”
Buildifier.

#+BEGIN_SRC sh :tangle buildifier :shebang "#!/bin/bash" :var dir=(file-name-unquote (expand-file-name default-directory))
# Fake waiting for file input.
cat > /dev/null

# Wait for signal file to exist.
while [[ ! -e "${dir:?}/signal" ]]; do
  sleep 1
done

# Fake some Buildifier output.
cat -- "${dir:?}/buildifier.json"
#+END_SRC
