-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): improve support for mixed linters when using IDEs (nrwl…
- Loading branch information
Showing
13 changed files
with
276 additions
and
62 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 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 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
120 changes: 120 additions & 0 deletions
120
packages/workspace/src/migrations/update-9-1-0/update-lint-config.spec.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,120 @@ | ||
import { chain, Tree } from '@angular-devkit/schematics'; | ||
import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { callRule, runMigration } from '../../utils/testing'; | ||
import { updateWorkspace } from '@nrwl/workspace/src/utils/workspace'; | ||
|
||
describe('Update 9.1.0', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = Tree.empty(); | ||
tree = createEmptyWorkspace(tree); | ||
}); | ||
|
||
it('should update tslint.json', async () => { | ||
tree = await callRule( | ||
chain([ | ||
updateWorkspace(workspace => { | ||
workspace.projects.add({ | ||
name: 'proj1', | ||
root: 'proj1', | ||
architect: { | ||
lint: { | ||
builder: '@angular-devkit/build-angular:tslint' | ||
} | ||
} | ||
}); | ||
workspace.projects.add({ | ||
name: 'proj2', | ||
root: 'proj2', | ||
architect: { | ||
lint: { | ||
builder: '@angular-devkit/build-angular:tslint' | ||
} | ||
} | ||
}); | ||
}), | ||
updateJsonInTree('proj1/tslint.json', () => ({ | ||
rules: {} | ||
})), | ||
updateJsonInTree('proj2/tslint.json', () => ({ | ||
rules: {}, | ||
linterOptions: { | ||
exclude: ['whatever'] | ||
} | ||
})) | ||
]), | ||
tree | ||
); | ||
|
||
const result = await runMigration('update-lint-config-9-1-0', {}, tree); | ||
|
||
expect(readJsonInTree(result, 'proj1/tslint.json')).toEqual({ | ||
rules: {}, | ||
linterOptions: { | ||
exclude: ['!**/*'] | ||
} | ||
}); | ||
|
||
expect(readJsonInTree(result, 'proj2/tslint.json')).toEqual({ | ||
rules: {}, | ||
linterOptions: { | ||
exclude: ['!**/*', 'whatever'] | ||
} | ||
}); | ||
}); | ||
|
||
it('should update .eslintrc', async () => { | ||
tree = await callRule( | ||
chain([ | ||
updateWorkspace(workspace => { | ||
workspace.projects.add({ | ||
name: 'proj1', | ||
root: 'proj1', | ||
architect: { | ||
lint: { | ||
builder: '@nrwl/linter:lint', | ||
options: { | ||
config: 'proj1/.eslintrc' | ||
} | ||
} | ||
} | ||
}); | ||
workspace.projects.add({ | ||
name: 'proj2', | ||
root: 'proj2', | ||
architect: { | ||
lint: { | ||
builder: '@nrwl/linter:lint', | ||
options: { | ||
config: 'proj2/.eslintrc' | ||
} | ||
} | ||
} | ||
}); | ||
}), | ||
updateJsonInTree('proj1/.eslintrc', () => ({ | ||
rules: {} | ||
})), | ||
updateJsonInTree('proj2/.eslintrc', () => ({ | ||
rules: {}, | ||
ignorePatterns: ['whatever'] | ||
})) | ||
]), | ||
tree | ||
); | ||
|
||
const result = await runMigration('update-lint-config-9-1-0', {}, tree); | ||
|
||
expect(readJsonInTree(result, 'proj1/.eslintrc')).toEqual({ | ||
rules: {}, | ||
ignorePatterns: ['!**/*'] | ||
}); | ||
|
||
expect(readJsonInTree(result, 'proj2/.eslintrc')).toEqual({ | ||
rules: {}, | ||
ignorePatterns: ['!**/*', 'whatever'] | ||
}); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/workspace/src/migrations/update-9-1-0/update-lint-config.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,56 @@ | ||
import { SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { readWorkspace, updateJsonInTree } from '@nrwl/workspace'; | ||
|
||
function updateLintConfigurations(host: Tree, context: SchematicContext) { | ||
const workspaceJson = readWorkspace(host); | ||
Object.values(workspaceJson.projects).forEach((config: any) => { | ||
if (!config.architect || !config.architect.lint) return; | ||
if (config.architect.lint.builder === '@nrwl/linter:lint') { | ||
updateJson( | ||
json => { | ||
// Prefix it so that previously ignored files will override the whitelist. | ||
json.ignorePatterns = ['!**/*', ...(json.ignorePatterns || [])]; | ||
return json; | ||
}, | ||
config.architect.lint.options.config, | ||
host, | ||
context | ||
); | ||
} | ||
if ( | ||
config.architect.lint.builder === '@angular-devkit/build-angular:tslint' | ||
) { | ||
updateJson( | ||
json => { | ||
json.linterOptions = { | ||
...json.linterOptions, | ||
// Prefix it so that previously ignored files will override the whitelist. | ||
exclude: [ | ||
'!**/*', | ||
...((json.linterOptions && json.linterOptions.exclude) || []) | ||
] | ||
}; | ||
return json; | ||
}, | ||
`${config.root}/tslint.json`, | ||
host, | ||
context | ||
); | ||
} | ||
}); | ||
} | ||
|
||
function updateJson(visitor, path, host, context) { | ||
try { | ||
if (host.exists(path)) { | ||
// In case tslint.json does not exist we don't want to create it. | ||
updateJsonInTree(path, visitor)(host, context); | ||
} | ||
} catch { | ||
context.logger.warn(`Could not update ${path}`); | ||
} | ||
} | ||
|
||
export default function() { | ||
return updateLintConfigurations; | ||
} |
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 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
Oops, something went wrong.