forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint_javascript_files
More file actions
executable file
·88 lines (74 loc) · 3.1 KB
/
lint_javascript_files
File metadata and controls
executable file
·88 lines (74 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
#
# @license Apache-2.0
#
# Copyright (c) 2024 The Stdlib Authors.
#
# 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
#
# http://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.
# Script to lint and automatically fix JavaScript files.
#
# Usage: lint_javascript_files file1 [file2 file3 ...]
#
# Arguments:
#
# file1 File path.
# file2 File path.
# file3 File path.
#
# Environment variables:
#
# FIX 0 or 1 indicating whether to automatically fix errors.
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Flag indicating whether to automatically fix errors:
fix="${FIX:-0}"
# Files to lint:
files_to_lint="$*"
# Define the path to ESLint configuration file for linting examples:
eslint_examples_conf="${root}/etc/eslint/.eslintrc.examples.js"
# Define the path to ESLint configuration file for linting tests:
eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js"
# Define the path to ESLint configuration file for linting benchmarks:
eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js"
# Lint JavaScript source files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ' | sed 's/ $//')
# Build native addons if present:
packages=$(echo "${files}" | tr ' ' '\n' | sed 's/^lib\/node_modules\///g' | sed 's/\/lib\/.*//g' | sort | uniq)
for pkg in ${packages}; do
if [ -f "lib/node_modules/${pkg}/binding.gyp" ]; then
NODE_ADDONS_PATTERN="${pkg}" make install-node-addons
fi
done
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${files}"
fi
# Lint JavaScript command-line interfaces...
file=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${file}" ]]; then
make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${file}"
fi
# Lint JavaScript example files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
fi
# Lint JavaScript test files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
fi
# Lint JavaScript benchmark files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
fi