fix: improve formatting (#1732)

This commit is contained in:
Yoshiya Hinosawa 2019-02-12 02:57:26 +09:00 committed by Ryan Dahl
parent 90c7af27d7
commit d26655371b
17 changed files with 55 additions and 30 deletions

View File

@ -18,6 +18,7 @@ environment:
RUSTUP_HOME: $(RUST_DIR)\rustup
RUST_BACKTRACE: full
RUSTC_WRAPPER: sccache
PYTHONPATH: third_party\python_packages
SCCACHE_BUCKET: deno-sccache
AWS_ACCESS_KEY_ID: AKIAIVRN52PLDBP55LBQ
AWS_SECRET_ACCESS_KEY:

View File

@ -19,7 +19,8 @@ Before submitting, please make sure the following is done:
1. There are tests that cover the changes.
2. Ensure `./tools/test.py` passes.
3. Format your code with `deno ./tools/format.ts --allow-read --allow-run`.
3. Format your code with `PYTHONPATH=third_party/python_packages deno ./tools/format.ts --allow-read --allow-run`.
<!-- TODO: set PYTHONPATH in format.ts when run API has env option -->
4. Make sure `./tools/lint.py` passes.
## Changes to `third_party`

View File

@ -10,6 +10,7 @@ env:
- RUST_BACKTRACE=full
- CARGO_TARGET_DIR=$HOME/target
- PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH
- PYTHONPATH=third_party/python_packages
- RUSTC_WRAPPER=sccache
- SCCACHE_BUCKET=deno-sccache
- AWS_ACCESS_KEY_ID=AKIAIVRN52PLDBP55LBQ

View File

@ -116,7 +116,8 @@ Extra steps for Windows users:
./tools/test.py
# Format code.
deno ./tools/format.ts --allow-read --allow-run
PYTHONPATH=third_party/python_packages deno ./tools/format.ts --allow-read --allow-run
<!-- TODO: set PYTHONPATH in format.ts when run API has env option -->
Other useful commands:

View File

@ -245,8 +245,11 @@ test(function consoleTestError() {
try {
throw new MyError("This is an error");
} catch (e) {
assert(stringify(e).split("\n")[3]
.includes("MyError: This is an error"));
assert(
stringify(e)
.split("\n")[3]
.includes("MyError: This is an error")
);
}
});

View File

@ -107,7 +107,8 @@ function evaluate(code: string): void {
} else {
if (errInfo.isNativeError) {
const formattedError = formatError(
libdeno.errorToJSON(errInfo.thrown as Error));
libdeno.errorToJSON(errInfo.thrown as Error)
);
console.error(formattedError);
} else {
console.error("Thrown:", errInfo.thrown);

View File

@ -57,15 +57,20 @@ def import_data_from_gh_pages():
def get_binary_sizes(build_dir):
path_dict = {
"deno": os.path.join(build_dir, "deno" + executable_suffix),
"main.js": os.path.join(build_dir, "gen/bundle/main.js"),
"main.js.map": os.path.join(build_dir, "gen/bundle/main.js.map"),
"compiler.js": os.path.join(build_dir, "gen/bundle/compiler.js"),
"compiler.js.map": os.path.join(build_dir,
"gen/bundle/compiler.js.map"),
"snapshot_deno.bin": os.path.join(build_dir, "gen/snapshot_deno.bin"),
"snapshot_compiler.bin": os.path.join(build_dir,
"gen/snapshot_compiler.bin")
"deno":
os.path.join(build_dir, "deno" + executable_suffix),
"main.js":
os.path.join(build_dir, "gen/bundle/main.js"),
"main.js.map":
os.path.join(build_dir, "gen/bundle/main.js.map"),
"compiler.js":
os.path.join(build_dir, "gen/bundle/compiler.js"),
"compiler.js.map":
os.path.join(build_dir, "gen/bundle/compiler.js.map"),
"snapshot_deno.bin":
os.path.join(build_dir, "gen/snapshot_deno.bin"),
"snapshot_compiler.bin":
os.path.join(build_dir, "gen/snapshot_compiler.bin")
}
sizes = {}
for name, path in path_dict.items():

View File

@ -18,8 +18,7 @@ def fmt_test(deno_exe):
# Set DENO_DIR to //js/ so we don't have to rely on an intenet
# connection to download https://deno.land/x/std/prettier/main.ts
deno_dir = os.path.join(root_path, "js")
run(
[deno_exe, dst, "--fmt", "--allow-read"],
run([deno_exe, dst, "--fmt", "--allow-read"],
merge_env={"DENO_DIR": deno_dir})
with open(fixed_filename) as f:
expected = f.read()

View File

@ -10,12 +10,20 @@ const yapf = join("third_party", "python_packages", "bin", "yapf");
const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt");
const rustfmtConfig = ".rustfmt.toml";
const run = (...args: string[]) => {
const decoder = new TextDecoder();
async function run(...args: string[]): Promise<void> {
if (deno.platform.os === "win") {
args = ["cmd.exe", "/c", ...args];
}
return deno.run({ args, stdout: "null", stderr: "piped" }).status();
};
const p = deno.run({ args, stdout: "piped", stderr: "piped" });
const { code } = await p.status();
if (code !== 0) {
console.log(decoder.decode(await deno.readAll(p.stderr)));
console.log(decoder.decode(await deno.readAll(p.stdout)));
deno.exit(code);
}
}
(async () => {
console.log("clang_format");
@ -49,6 +57,7 @@ const run = (...args: string[]) => {
console.log("prettier");
await run(
lookupDenoPath(),
"--allow-read",
"--allow-write",
"js/deps/https/deno.land/x/std/prettier/main.ts",
"rollup.config.js",

View File

@ -45,7 +45,7 @@ def str2bool(v):
raise ValueError("Bad boolean value")
def integration_tests(deno_exe, test_filter = None):
def integration_tests(deno_exe, test_filter=None):
assert os.path.isfile(deno_exe)
tests = sorted([
filename for filename in os.listdir(tests_path)
@ -97,11 +97,12 @@ def integration_tests(deno_exe, test_filter = None):
print green_ok()
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--filter", help="Run specific tests")
parser.add_argument("--release", help="Use release build of Deno",
action="store_true")
parser.add_argument(
"--release", help="Use release build of Deno", action="store_true")
parser.add_argument("--executable", help="Use external executable of Deno")
args = parser.parse_args()

View File

@ -10,15 +10,18 @@ from permission_prompt_test import tty_capture
IS_TTY_TEST_TS = "tests/is_tty.ts"
def is_tty_test(deno_exe):
cmd = [deno_exe, IS_TTY_TEST_TS]
code, stdout, _ = tty_capture(cmd, b'')
assert code == 0
assert str(stdin.isatty()).lower() in stdout
def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
is_tty_test(deno_exe)
if __name__ == "__main__":
main()

View File

@ -15,8 +15,8 @@ tslint = os.path.join(third_party_path, "node_modules", "tslint", "bin",
os.chdir(root_path)
run([
"python", cpplint, "--filter=-build/include_subdir", "--repository=libdeno",
"--extensions=cc,h", "--recursive", "libdeno"
"python", cpplint, "--filter=-build/include_subdir",
"--repository=libdeno", "--extensions=cc,h", "--recursive", "libdeno"
])
run(["node", tslint, "-p", ".", "--exclude", "**/gen/**/*.ts"])

View File

@ -1,10 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { args, listen, env, exit, makeTempDirSync, readFile, run} from "deno";
import { args, listen, env, exit, makeTempDirSync, readFile, run } from "deno";
const name = args[1];
const test = {
needsRead: () => {
readFile("package.json")
readFile("package.json");
},
needsWrite: () => {
makeTempDirSync();

View File

@ -38,7 +38,6 @@ def test_no_color(deno_exe):
print green_ok()
def main(argv):
if len(argv) == 2:
build_dir = sys.argv[1]

View File

@ -255,8 +255,7 @@ def download_clang_format():
# Download clang by calling the clang update script.
def download_clang():
run(['python', tp('v8/tools/clang/scripts/update.py')],
env=google_env())
run(['python', tp('v8/tools/clang/scripts/update.py')], env=google_env())
def maybe_download_sysroot():

View File

@ -46,7 +46,8 @@ def unit_tests(deno_exe):
run_unit_test(deno_exe, "permR0W0N0E0U0")
run_unit_test(deno_exe, "permR1W0N0E0U0", ["--allow-read"])
run_unit_test(deno_exe, "permR0W1N0E0U0", ["--allow-write"])
run_unit_test(deno_exe, "permR1W1N0E0U0", ["--allow-read", "--allow-write"])
run_unit_test(deno_exe, "permR1W1N0E0U0",
["--allow-read", "--allow-write"])
run_unit_test(deno_exe, "permR1W0N1E0U0", ["--allow-read", "--allow-net"])
run_unit_test(deno_exe, "permR0W0N0E1U0", ["--allow-env"])
run_unit_test(deno_exe, "permR0W0N0E0U1", ["--allow-run"])

View File

@ -383,6 +383,7 @@ def parse_wrk_output(output):
def platform():
return {"linux2": "linux", "darwin": "mac", "win32": "win"}[sys.platform]
def mkdtemp():
# On Windows, set the base directory that mkdtemp() uses explicitly. If not,
# it'll use the short (8.3) path to the temp dir, which triggers the error