Skip to content

Commit

Permalink
fix: regression for eslint v6 (#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 25, 2020
1 parent d262178 commit 31fc503
Show file tree
Hide file tree
Showing 32 changed files with 764 additions and 90 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Expand Up @@ -3,7 +3,6 @@
**/dist
**/coverage
**/shared-fixtures
**/tests/integration/fixtures/**/*
**/.vscode
**/.nyc_output
packages/eslint-plugin-tslint/tests/test-tslint-rules-directory/alwaysFailRule.js
Expand Down
12 changes: 11 additions & 1 deletion packages/experimental-utils/src/ts-eslint/ESLint.ts
Expand Up @@ -341,6 +341,16 @@ namespace ESLint {
}
}

// We want to export this class always so it's easy for end users to consume.
// However on ESLint v6, this class will not exist, so we provide a fallback to make it clear
// The only users of this should be users scripting ESLint locally, so _they_ should have the correct version installed.
const _ESLint = (ESLintESLint ??
function (): void {
throw new Error(
'Attempted to construct an ESLint instance on less than ESLint v7.0.0',
);
}) as typeof ESLintBase;

/**
* The ESLint class is the primary class to use in Node.js applications.
* This class depends on the Node.js fs module and the file system, so you cannot use it in browsers.
Expand All @@ -349,6 +359,6 @@ namespace ESLint {
*
* @since 7.0.0
*/
class ESLint extends (ESLintESLint as typeof ESLintBase) {}
class ESLint extends _ESLint {}

export { ESLint };
2 changes: 2 additions & 0 deletions tests/integration/README.md
Expand Up @@ -16,3 +16,5 @@ These tests are setup to run within docker containers to ensure that each test i
1. Add a new entry to `run-all-tests.sh` by copy+pasting an existing command, and changing the name to match your new folder.
1. Run your integration test by running the single command you copied in the previous step.
- If your test finishes successfully, a `test.js.snap` will be created.

If you run your test and see the test fail with `Cannot find module './lint-output.json' from 'test.js'`, this means that ESLint errored whilst attempting to run the lint command.
19 changes: 19 additions & 0 deletions tests/integration/docker-compose.yml
Expand Up @@ -97,3 +97,22 @@ services:
- /usr/eslint-plugin/tests
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/markdown:/usr/linked

eslint-v6:
build: ./fixtures/eslint-v6
container_name: 'eslint-v6'
volumes:
# Runtime link to the relevant built @typescript-eslint packages and integration test utils,
# but apply an empty volume for the package tests, we don't need those.
- ../../package.json/:/usr/root-package.json
- ./utils/:/usr/utils
- ../../packages/parser/:/usr/parser
- /usr/parser/tests
- ../../packages/typescript-estree/:/usr/typescript-estree
- /usr/typescript-estree/tests
- ../../packages/experimental-utils/:/usr/experimental-utils
- /usr/experimental-utils/tests
- ../../packages/eslint-plugin/:/usr/eslint-plugin
- /usr/eslint-plugin/tests
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/eslint-v6:/usr/linked
12 changes: 12 additions & 0 deletions tests/integration/fixtures/eslint-v6/.eslintrc.js
@@ -0,0 +1,12 @@
module.exports = {
root: true,
// Local version of @typescript-eslint/parser
parser: '@typescript-eslint/parser',
plugins: [
// Local version of @typescript-eslint/eslint-plugin
'@typescript-eslint',
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
};
17 changes: 17 additions & 0 deletions tests/integration/fixtures/eslint-v6/Dockerfile
@@ -0,0 +1,17 @@
FROM node:erbium

# Copy the test.sh into the container. Every other file will be linked, rather
# than copied to allow for changes without rebuilds wherever possible
WORKDIR /usr
COPY ./test.sh /usr/

# Create file which will be executed by jest
# to assert that the lint output is what we expect
RUN echo "const actualLintOutput = require('./lint-output.json');\n" \
"\n" \
"test('it should produce the expected lint ouput', () => {\n" \
" expect(actualLintOutput).toMatchSnapshot();\n" \
"});\n" > test.js

# Run the integration test
CMD [ "./test.sh" ]
1 change: 1 addition & 0 deletions tests/integration/fixtures/eslint-v6/index.ts
@@ -0,0 +1 @@
const noSemi: any = true;
28 changes: 28 additions & 0 deletions tests/integration/fixtures/eslint-v6/test.js.snap
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`it should produce the expected lint ouput 1`] = `
Array [
Object {
"errorCount": 1,
"filePath": "/usr/linked/index.ts",
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"messages": Array [
Object {
"column": 15,
"endColumn": 18,
"endLine": 1,
"line": 1,
"message": "Unexpected any. Specify a different type.",
"messageId": "unexpectedAny",
"nodeType": "TSAnyKeyword",
"ruleId": "@typescript-eslint/no-explicit-any",
"severity": 2,
},
],
"source": "const noSemi: any = true;
",
"warningCount": 0,
},
]
`;
22 changes: 22 additions & 0 deletions tests/integration/fixtures/eslint-v6/test.sh
@@ -0,0 +1,22 @@
#!/bin/bash
set -exuo pipefail

# Generate the package.json to use
node /usr/utils/generate-package-json.js

# Install dependencies
npm install
npm install eslint@6.0.0

# Use the local volumes for our own packages
npm install $(npm pack /usr/typescript-estree | tail -1)
npm install $(npm pack /usr/parser | tail -1)
npm install $(npm pack /usr/experimental-utils | tail -1)
npm install $(npm pack /usr/eslint-plugin | tail -1)

# Run the linting
# (the "|| true" helps make sure that we run our tests on failed linting runs as well)
npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.js /usr/linked/**/*.ts || true

# Run our assertions against the linting output
npx jest /usr/test.js --snapshotResolver=/usr/utils/jest-snapshot-resolver.js
5 changes: 5 additions & 0 deletions tests/integration/fixtures/eslint-v6/tsconfig.json
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": true
}
}
8 changes: 6 additions & 2 deletions tests/integration/fixtures/markdown/Doc.md
@@ -1,6 +1,7 @@
Some extra text to verify that the markdown plugin is ignoring anything that is not a code block.

expected no-console error:

```jsx
import { Button } from 'antd';

Expand All @@ -20,6 +21,7 @@ function MyComp() {

expected no-explicit-any error:
expected no-console error:

```jsx
import { Button } from 'antd';

Expand All @@ -38,6 +40,7 @@ function MyComp(): any {
```

expected no-console error:

```js
function foo() {
console.log('test');
Expand All @@ -46,24 +49,25 @@ function foo() {

expected no-explicit-any error:
expected no-console error:

```js
function foo(): any {
console.log('test');
}
```


expected no-explicit-any error:
expected no-console error:

```javascript
function foo(): any {
console.log('test');
}
```


expected no-explicit-any error:
expected no-console error:

```node
function foo(): any {
console.log('test');
Expand Down

0 comments on commit 31fc503

Please sign in to comment.