Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP test flat config
  • Loading branch information
lydell committed Jul 27, 2023
commit 39b7c47beceb227e26dda044194471230e4afa36
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
!/.*
/build/
/test-config/
build/**
test-config/**
4 changes: 3 additions & 1 deletion .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// This file is only used in `./.eslintrc.js` and in the tests – it’s not part
// of the eslint-config-prettier npm package.
//
// NOTE: Keep this file in sync with `./eslint.base.config.js`!

const config = require(".");

Expand Down Expand Up @@ -40,7 +42,7 @@ module.exports = {
"indent": "off",
"linebreak-style": "off",
"no-dupe-keys": "error",
"strict": "error",
"strict": ["error", "global"],
"prefer-spread": "off",
"require-jsdoc": "off",
"prettier/prettier": "error",
Expand Down
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// sharable config from npm and then include the configs exposed by this package
// as an “eat your own dogfood” test. That feels like a good test, but
// complicates things a little sometimes.
//
// NOTE: Keep this file in sync with `./eslint.config.js`!

module.exports = {
extends: ["./.eslintrc.base.js", "./index.js", "./prettier.js"],
Expand Down Expand Up @@ -32,7 +34,7 @@ module.exports = {
},
},
{
files: ["*.test.js"],
files: ["**/*.test.js"],
env: { jest: true },
},
],
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ jobs:
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci --no-audit

- name: ESLint
- name: ESLint – flat
run: npx eslint .

- name: ESLint – eslintrc
run: npx eslint .
env:
ESLINT_USE_FLAT_CONFIG: "false"

- name: Prettier
run: npx prettier --check .

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ Finally, you need to mention the plugin in several places:

When you’re done, run `npm test` to verify that you got it all right. It runs several other npm scripts:

- `"test:lint"` makes sure that the files in `test-lint/` pass ESLint when the exclusions from eslint-config-prettier are used. It also lints the code of eslint-config-prettier itself, and checks that Prettier has been run on all files.
- `"test:prettier"` checks that Prettier has been run on all files.
- `"test:eslint"` makes sure that the files in `test-lint/` pass ESLint when the exclusions from eslint-config-prettier are used. It also lints the code of eslint-config-prettier itself.
- `"test:lint-verify-fail"` is run by a test in `test/lint-verify-fail.test.js`.
- `"test:lint-rules"` is run by a test in `test/rules.test.js`.
- `"test:jest"` runs unit tests that check a number of things:
Expand Down
93 changes: 93 additions & 0 deletions eslint.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use strict";

// This file is only used in `./eslint.config.js` and in the tests – it’s not part
// of the eslint-config-prettier npm package.
//
// NOTE: Keep this file in sync with `./.eslintrc.base.js`!

const fs = require("fs");
const path = require("path");
const babelOld = require("eslint-plugin-babel");
const babelNew = require("@babel/eslint-plugin");
const babelParser = require("@babel/eslint-parser");
const flowtype = require("eslint-plugin-flowtype");
const globals = require("globals");
const google = require("eslint-config-google");
const react = require("eslint-plugin-react");
const unicorn = require("eslint-plugin-unicorn");
const vue = require("eslint-plugin-vue");
const eslintrcBase = require("./.eslintrc.base");

module.exports = [
{
ignores: fs
.readFileSync(path.join(__dirname, ".eslintignore"), "utf8")
.trim()
.split("\n"),
},
{
// TODO
ignores: ["test-lint/flowtype.js"],
},
google,
{
plugins: {
"babel": babelOld,
"@babel": babelNew,
},
},
{
plugins: {
flowtype,
},
rules: flowtype.configs.recommended.rules,
settings: flowtype.configs.recommended.settings,
},
{
plugins: {
react,
},
rules: react.configs.all.rules,
},
{
plugins: {
unicorn,
},
rules: unicorn.configs.recommended.rules,
},
{
plugins: {
vue,
},
rules: {
...vue.configs.base.rules,
...vue.configs.base.essential,
...vue.configs.base["strongly-recommended"],
...vue.configs.base.recommended,
},
},
{
languageOptions: {
ecmaVersion: eslintrcBase.parserOptions.ecmaVersion,
sourceType: eslintrcBase.parserOptions.sourceType,
globals: {
...globals.es6,
...globals.node,
},
parser: babelParser,
parserOptions: {
babelOptions: {
plugins: [
"@babel/plugin-transform-react-jsx",
"@babel/plugin-syntax-flow",
],
},
loggerFn: eslintrcBase.parserOptions.loggerFn,
ecmaFeatures: eslintrcBase.parserOptions.ecmaFeatures,
},
},
rules: eslintrcBase.rules,
settings: eslintrcBase.settings,
},
...eslintrcBase.overrides,
];
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";

// This is the internal ESLint config for this project itself – it’s not part of
// the eslint-config-prettier npm package. The idea here is to extend some
// sharable config from npm and then include the configs exposed by this package
// as an “eat your own dogfood” test. That feels like a good test, but
// complicates things a little sometimes.
//
// NOTE: Keep this file in sync with `./.eslintrc.js`!

const globals = require("globals");
const base = require("./eslint.base.config");
const index = require(".");
const prettier = require("./prettier");
const eslintrc = require("./.eslintrc");

module.exports = [
...base,
index,
prettier,
{
rules: eslintrc.rules,
},
...eslintrc.overrides.map(({ env = {}, ...override }) => ({
...override,
languageOptions: {
globals: Object.entries(env).reduce(
(acc, [key, enabled]) => (enabled ? { ...acc, ...globals[key] } : acc),
{}
),
},
})),
];
Loading