Skip to content

Commit

Permalink
Merge pull request #167 from prettier/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell authored Nov 29, 2020
2 parents 80463a4 + 891c1d1 commit 897abbc
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 59 deletions.
1 change: 1 addition & 0 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
},
rules: {
indent: "off",
"linebreak-style": "off",
"no-dupe-keys": "error",
strict: "error",
"prefer-spread": "off",
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Check

on:
push:
branches:
- "master"
pull_request:

jobs:
main:
runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest]
node-version: [15.x]

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci

- name: ESLint
run: npx --no-install eslint .

- name: Prettier
run: npx --no-install prettier --check .
39 changes: 0 additions & 39 deletions .github/workflows/ci.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
push:
branches:
- "master"
pull_request:

jobs:
main:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [10.x, 12.x, 14.x, 15.x]

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci

- name: Jest
run: npx --no-install jest

- name: CLI sanity
run: npm run test:cli-sanity

- name: CLI sanity warning
run: npm run test:cli-sanity-warning
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/test-config/
.vscode
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@typescript-eslint/eslint-plugin": "4.8.2",
"@typescript-eslint/parser": "4.8.2",
"babel-eslint": "10.1.0",
"cross-spawn": "7.0.3",
"doctoc": "1.4.0",
"eslint": "7.14.0",
"eslint-config-google": "0.14.0",
Expand Down
3 changes: 3 additions & 0 deletions test-lint/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"endOfLine": "auto"
}
23 changes: 15 additions & 8 deletions test/lint-verify-fail.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"use strict";

const childProcess = require("child_process");
const fs = require("fs");
const path = require("path");
const spawn = require("cross-spawn");

const ROOT = path.join(__dirname, "..");
const ruleFiles = fs
.readdirSync(".")
.readdirSync(ROOT)
.filter((name) => !name.startsWith(".") && name.endsWith(".js"));

describe("test-lint/ causes errors without eslint-config-prettier", () => {
const result = spawn.sync(
const result = childProcess.spawnSync(
"npm",
["run", "test:lint-verify-fail", "--silent"],
{ encoding: "utf8" }
{ encoding: "utf8", shell: true }
);
const output = JSON.parse(result.stdout);

Expand All @@ -31,11 +32,17 @@ describe("test-lint/ causes errors without eslint-config-prettier", () => {

test("must only cause errors related to itself", () => {
if (name === "index") {
expect(ruleIds.every((ruleId) => !ruleId.includes("/"))).toBe(true);
expect(
ruleIds
.filter((ruleId) => ruleId.includes("/"))
.concat("no ruleId should not contain a slash")
).toEqual(["no ruleId should not contain a slash"]);
} else {
expect(ruleIds.every((ruleId) => ruleId.startsWith(`${name}/`))).toBe(
true
);
expect(
ruleIds
.filter((ruleId) => !ruleId.startsWith(`${name}/`))
.concat(`every ruleId should start with: ${name}/`)
).toEqual([`every ruleId should start with: ${name}/`]);
}
});
});
Expand Down
28 changes: 17 additions & 11 deletions test/rules.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"use strict";

const childProcess = require("child_process");
const fs = require("fs");
const path = require("path");
const rimraf = require("rimraf");
const spawn = require("cross-spawn");
const pkg = require("../package.json");
const eslintConfig = require("../.eslintrc");
const eslintConfigBase = require("../.eslintrc.base");

const TEST_CONFIG_DIR = "test-config";
const ROOT = path.join(__dirname, "..");
const TEST_CONFIG_DIR = path.join(ROOT, "test-config");

const ruleFiles = fs
.readdirSync(".")
.readdirSync(ROOT)
.filter((name) => !name.startsWith(".") && name.endsWith(".js"));
const configFiles = fs
.readdirSync(".")
.readdirSync(ROOT)
.filter((name) => name.startsWith(".eslintrc"));

beforeAll(() => {
Expand Down Expand Up @@ -71,7 +72,9 @@ describe("all rule files have tests in test-lint/", () => {
: ruleFileName === "@typescript-eslint.js"
? "@typescript-eslint.ts"
: ruleFileName;
expect(fs.existsSync(path.join("test-lint", testFileName))).toBe(true);
expect(fs.existsSync(path.join(ROOT, "test-lint", testFileName))).toBe(
true
);
});
});
});
Expand All @@ -89,7 +92,7 @@ describe("all rule files are included in the ESLint config", () => {
});

describe("all plugin rule files are mentioned in the README", () => {
const readme = fs.readFileSync("README.md", "utf8");
const readme = fs.readFileSync(path.join(ROOT, "README.md"), "utf8");
ruleFiles
.filter((ruleFileName) => ruleFileName !== "index.js")
.forEach((ruleFileName) => {
Expand All @@ -104,7 +107,7 @@ describe("all plugin rule files are mentioned in the README", () => {
});

describe("all special rules are mentioned in the README", () => {
const readme = fs.readFileSync("README.md", "utf8");
const readme = fs.readFileSync(path.join(ROOT, "README.md"), "utf8");
const specialRuleNames = [].concat(
...ruleFiles.map((ruleFileName) => {
const rules = require(`../${ruleFileName}`).rules;
Expand Down Expand Up @@ -135,9 +138,11 @@ describe('all rules are set to "off" or 0', () => {
});

test("there are no unknown rules", () => {
const result = spawn.sync("npm", ["run", "test:lint-rules", "--silent"], {
encoding: "utf8",
});
const result = childProcess.spawnSync(
"npm",
["run", "test:lint-rules", "--silent"],
{ encoding: "utf8", shell: true }
);
const output = JSON.parse(result.stdout);

output[0].messages.forEach((message) => {
Expand All @@ -147,8 +152,9 @@ test("there are no unknown rules", () => {

test("support omitting all deprecated rules", () => {
const run = (env = {}) =>
spawn.sync("npm", ["run", "test:deprecated"], {
childProcess.spawnSync("npm", ["run", "test:deprecated"], {
encoding: "utf8",
shell: true,
env: {
...process.env,
...env,
Expand Down

0 comments on commit 897abbc

Please sign in to comment.