Skip to content

Commit

Permalink
chore(eslint-plugin-cdk): fix tests and expectations (#12831)
Browse files Browse the repository at this point in the history
The previous change - 9a81faa - to add test cases to this package
had a bug. Two different eslint rules were being applied
simultaneously creating corrupt expectation.

Fixing the test so it only runs the specific eslint rule for that
fixture, and fixing the expectation.

At the same time, added a test case that was previously missed.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored Feb 3, 2021
1 parent 8d3aaba commit 2aba609
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
32 changes: 16 additions & 16 deletions tools/eslint-plugin-cdk/test/rules/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@ import * as path from 'path';
const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = path.join(__dirname, '../../lib/rules');

const linter = new ESLint({
baseConfig: {
parser: '@typescript-eslint/parser',
plugins: ['rulesdir'],
rules: {
quotes: [ 'error', 'single', { avoidEscape: true }],
'rulesdir/no-core-construct': [ 'error' ],
'rulesdir/no-qualified-construct': [ 'error' ],
}
},
rulePaths: [
path.join(__dirname, '../../lib/rules'),
],
fix: true,
});
let linter: ESLint;

const outputRoot = path.join(process.cwd(), '.test-output');
fs.mkdirpSync(outputRoot);
Expand All @@ -28,10 +14,24 @@ const fixturesRoot = path.join(__dirname, 'fixtures');

fs.readdirSync(fixturesRoot).filter(f => fs.lstatSync(path.join(fixturesRoot, f)).isDirectory()).forEach(d => {
describe(d, () => {
const fixturesDir = path.join(fixturesRoot, d);

beforeAll(() => {
linter = new ESLint({
baseConfig: {
parser: '@typescript-eslint/parser',
},
overrideConfigFile: path.join(fixturesDir, 'eslintrc.js'),
rulePaths: [
path.join(__dirname, '../../lib/rules'),
],
fix: true,
});
});

const outputDir = path.join(outputRoot, d);
fs.mkdirpSync(outputDir);

const fixturesDir = path.join(fixturesRoot, d);
const fixtureFiles = fs.readdirSync(fixturesDir).filter(f => f.endsWith('.ts') && !f.endsWith('.expected.ts'));

fixtureFiles.forEach(f => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: ['rulesdir'],
rules: {
'rulesdir/no-core-construct': [ 'error' ],
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Construct } from 'constructs'
import * as cdk from '@aws-cdk/core';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct as CoreConstruct } from '@aws-cdk/core';

let x: CoreConstruct;
let y: Construct;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Construct } from 'constructs'
import * as cdk from '@aws-cdk/core';

let x: cdk.Construct;
let y: Construct;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: ['rulesdir'],
rules: {
'rulesdir/no-qualified-construct': [ 'error' ],
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as cdk from '@aws-cdk/core';
import * as constructs from 'constructs';

let x: constructs.Construct;
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

let x: Construct;

0 comments on commit 2aba609

Please sign in to comment.