-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into revert/add-new-asset-interfaces
- Loading branch information
Showing
9 changed files
with
117 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ESLint } from 'eslint'; | ||
import * as fs from 'fs-extra'; | ||
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, | ||
}); | ||
|
||
const outputRoot = path.join(process.cwd(), '.test-output'); | ||
fs.mkdirpSync(outputRoot); | ||
|
||
const fixturesRoot = path.join(__dirname, 'fixtures'); | ||
|
||
fs.readdirSync(fixturesRoot).filter(f => fs.lstatSync(path.join(fixturesRoot, f)).isDirectory()).forEach(d => { | ||
describe(d, () => { | ||
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 => { | ||
test(f, async (done) => { | ||
const actualFile = await lintAndFix(path.join(fixturesDir, f), outputDir); | ||
const expectedFile = path.join(fixturesDir, `${path.basename(f, '.ts')}.expected.ts`); | ||
if (!fs.existsSync(expectedFile)) { | ||
done.fail(`Expected file not found. Generated output at ${actualFile}`); | ||
} | ||
const actual = await fs.readFile(actualFile, { encoding: 'utf8' }); | ||
const expected = await fs.readFile(expectedFile, { encoding: 'utf8' }); | ||
if (actual !== expected) { | ||
done.fail(`Linted file did not match expectations. Expected: ${expectedFile}. Actual: ${actualFile}`); | ||
} | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
async function lintAndFix(file: string, outputDir: string) { | ||
const newPath = path.join(outputDir, path.basename(file)) | ||
let result = await linter.lintFiles(file); | ||
await ESLint.outputFixes(result.map(r => { | ||
r.filePath = newPath; | ||
return r; | ||
})); | ||
return newPath; | ||
} |
8 changes: 8 additions & 0 deletions
8
...lint-plugin-cdk/test/rules/fixtures/no-qualified-construct/qualified-heritage.expected.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 } from '@aws-cdk/core'; | ||
|
||
class MyConstruct extends Construct { | ||
} |
4 changes: 4 additions & 0 deletions
4
tools/eslint-plugin-cdk/test/rules/fixtures/no-qualified-construct/qualified-heritage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
|
||
class MyConstruct extends cdk.Construct { | ||
} |
4 changes: 4 additions & 0 deletions
4
.../eslint-plugin-cdk/test/rules/fixtures/no-qualified-construct/qualified-usage.expected.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as constructs from 'constructs'; | ||
|
||
let x: constructs.Construct; |
3 changes: 3 additions & 0 deletions
3
tools/eslint-plugin-cdk/test/rules/fixtures/no-qualified-construct/qualified-usage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
|
||
let x: cdk.Construct; |
44 changes: 0 additions & 44 deletions
44
tools/eslint-plugin-cdk/test/rules/no-core-construct.test.ts
This file was deleted.
Oops, something went wrong.