Anders Kaseorg
c6b372b471
js: Simplify indexing arrays from the end with Array#at.
...
https://github.com/tc39/proposal-relative-indexing-method
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-24 09:58:54 -08:00
Anders Kaseorg
0b03628324
js: Shorten Object.prototype.hasOwnProperty.call to Object.hasOwn.
...
https://github.com/tc39/proposal-accessible-object-hasownproperty
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-24 09:57:09 -08:00
Anders Kaseorg
6cd694b8e3
eslint: Fix unicorn/no-array-callback-reference.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Anders Kaseorg
552f4e3d22
eslint: Fix unicorn/no-array-for-each.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Anders Kaseorg
72d6ff3c3b
docs: Fix more capitalization issues.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-23 11:46:55 -07:00
Anders Kaseorg
73a14bee6f
eslint: Fix unicorn/escape-case and unicorn/no-hex-escape.
...
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/escape-case.md
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-hex-escape.md
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Anders Kaseorg
6ec808b8df
js: Add "use strict" directive to CommonJS files.
...
ES and TypeScript modules are strict by default and don’t need this
directive. ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
Anders Kaseorg
b65d2e063d
js: Reformat with Prettier.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
8046b6477a
js: Remove extra consecutive spaces.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
883e2fd325
js: Remove inner spacing from object literals.
...
We’re configuring Prettier with bracketSpacing: false. Generated by
ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
f3726db89a
js: Normalize strings to double quotes.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg
e014ea966a
eslint: Enable comma-dangle for functions.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg
615b7fcc2c
eslint: Enable arrow-body-style.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
Anders Kaseorg
aa912ef759
mdiff: Convert formatter, aliases from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-05-26 23:33:40 -07:00
Anders Kaseorg
c9dbd13189
js: Convert _.has to Object.prototype.hasOwnProperty.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-25 14:09:39 -08:00
Anders Kaseorg
ac7b09d57e
js: Convert _.map(a, …) to a.map(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitCallExpression(path) {
const { callee, arguments: args } = path.node;
if (
n.MemberExpression.check(callee) &&
!callee.computed &&
n.Identifier.check(callee.object) &&
callee.object.name === "_" &&
n.Identifier.check(callee.property) &&
callee.property.name === "map" &&
args.length === 2 &&
checkExpression(args[0]) &&
checkExpression(args[1])
) {
const [arr, fn] = args;
path.replace(
b.callExpression(b.memberExpression(arr, b.identifier("map")), [
n.FunctionExpression.check(fn) ||
n.ArrowFunctionExpression.check(fn)
? b.arrowFunctionExpression(
fn.params,
n.BlockStatement.check(fn.body) &&
fn.body.body.length === 1 &&
n.ReturnStatement.check(fn.body.body[0])
? fn.body.body[0].argument || b.identifier("undefined")
: fn.body
)
: fn,
])
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Tim Abbott
bdb3da4504
eslint: Add key-spacing linter rule.
...
Apparently, we didn't have one of these, and thus had a moderate
number of generally very old violations in the codebase. Fix this and
clear the ones that exist..
2018-12-18 10:41:06 -08:00
Tim Abbott
b2939cdf19
lint: Fix comma spacing in node tests.
...
I apparently failed to check the tests codebase before merging the
last linter commit. Oops.
2018-12-07 13:14:28 -08:00
Shubham Dhama
cc03f9fb8f
eslint: Enable space-infix-ops rule.
...
More about rule at https://eslint.org/docs/rules/space-infix-ops
2018-06-05 00:47:35 +05:30
Andy Perez
fc2298ec54
node tests: Add nice diffs to js markdown tests.
...
Fix #3915
2017-12-18 19:03:38 -05:00