Skip to content

Commit

Permalink
Tested and fixed importing/using recommended config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Wilson committed Sep 17, 2021
1 parent 7c28cbc commit eded332
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
node_modules
/test/fixture
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prepare": "husky install",
"docs": "PARSER=none ts-node --transpile-only scripts/docs.ts",
"build": "tsc -p tsconfig.build.json && yarn run docs",
"test": "mocha -r ts-node/register --extension=ts test/**/*.test.ts",
"test": "mocha -r ts-node/register --extension=ts 'test/**/*.test.ts'",
"test:ts": "PARSER=ts yarn test",
"test:babel": "PARSER=babel yarn test",
"test:v6": "PARSER=v6 yarn test",
Expand All @@ -39,7 +39,7 @@
"@types/eslint": "^7.2.13",
"@types/estree": "^0.0.50",
"@types/estree-jsx": "^0.0.1",
"@types/mocha": "^8.2.3",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
Expand All @@ -59,7 +59,7 @@
"eslint": "6.x-7.x"
},
"lint-staged": {
"*.{js,ts}": [
"*.ts": [
"eslint --fix",
"prettier --write"
]
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ const allRules = {
"style-prop": styleProp,
};

export default {
// Must be module.exports for eslint to load everything
module.exports = {
rules: allRules,
configs: {
recommended: {
plugins: "solid",
plugins: ["solid"],
env: {
browser: true,
es6: true,
},
parserOptions: {
ecmaVersion: 6,
ecmaFeatures: {
jsx: true,
impliedStrict: true,
},
},
rules: {
Expand Down
51 changes: 51 additions & 0 deletions test/fixture.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import execa from "execa";
import path from "path";
import assert from "assert";
import fs from "fs/promises";

const nodeModulesFileForTesting = path.resolve(
__dirname,
"..",
"node_modules",
"eslint-plugin-solid.js"
);

const fixtureCwd = path.resolve(__dirname, "fixture");

// We can't use `yarn bin` because it uses the eslint-v6 bin
const eslintPath = require.resolve("eslint/bin/eslint.js");

describe("fixture", function () {
this.slow(500);

before(async () => {
// We're trying to require the package we're currently in; we can work around
// this by putting a skeleton file inside `node_modules` that requires the top
// level directory.
await fs.writeFile(nodeModulesFileForTesting, `module.exports = require("..");\n`);
});

after(async () => {
await fs.unlink(nodeModulesFileForTesting);
});

it("loads the plugin without crashing", async () => {
const { exitCode } = await execa.node(eslintPath, ["--print-config", "super-simple.js"], {
cwd: fixtureCwd,
});
assert.strictEqual(exitCode, 0);
});

it("produces reasonable lint errors", async () => {
try {
await execa.node(eslintPath, ["super-simple.js"], {
cwd: fixtureCwd,
});
} catch (error) {
assert.strictEqual(error.exitCode, 1);
assert.match(error.stdout, /'Component' is not defined/);
assert.match(error.stdout, /solid\/jsx-no-undef/);
assert.match(error.stdout, /1 problem \(1 error, 0 warnings\)/);
}
});
});
5 changes: 5 additions & 0 deletions test/fixture/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root": true,
"extends": "plugin:solid/recommended",
"plugins": ["solid"]
}
1 change: 1 addition & 0 deletions test/fixture/super-simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let el = <Component />;
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==

"@types/mocha@^8.2.3":
version "8.2.3"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.2.3.tgz#bbeb55fbc73f28ea6de601fbfa4613f58d785323"
integrity sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==
"@types/mocha@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
integrity sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==

"@types/node@*":
version "16.4.10"
Expand Down

0 comments on commit eded332

Please sign in to comment.