Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various QoL with TSLint and Docs #12655

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `/bin` Folder

This folder includes binaries that are linked when globally linking this repository.

Each file in this directory follows this pattern:

1. JavaScript only.
1. Requires `../lib/bootstrap-local.js` to bootstrap TypeScript and Node integration.
1. Requires `../lib/packages` and use the package metadata to find the binary script for the
package the script is bootstrapping.
1. Call out main, or simply require the file if it has no export.

`devkit-admin` does not follow this pattern as it needs to setup logging and run some localized
logic.

In order to add a new script, you should make sure it's in the root `package.json`, so people
linking this repo get a reference to the script.
25 changes: 25 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# `/docs` Folder

This folder is used for all documentation. It contains a number of subfolders with short
descriptions here.

## `/docs/design`

Design documents on GitHub, in Markdown format. The number of design documents available is limited.

## `/docs/documentation`

THIS FOLDER IS DEPRECATED AND SHOULD NOT BE UPDATED ANYMORE. Documentation is now available on
angular.io and can be updated on the main [angular/angular](https://github.com/angular/angular)
repo.

Markdown files used to publish to the [GitHub Wiki](https://github.com/angular/angular-cli/wiki).

## `/docs/process`

Description of various caretaker and workflow processes.

## `/docs/specifications`

Specifications for support of Angular CLI features. These are meant to be read directly on GitHub
by developers of libraries who want to integrate with the Angular CLI.
3 changes: 3 additions & 0 deletions etc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `/etc` Folder

This folder is for files that doesn't fit in other directories in the root folder.
3 changes: 3 additions & 0 deletions etc/rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TsLint Rules

This folder contains custom TsLint rules specific to this repository.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rules/tsconfig.json → etc/rules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// things faster.
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/rules",
"outDir": "../../dist/etc/rules",
"baseUrl": ""
},
"exclude": [
Expand Down
16 changes: 16 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `/lib` Folder

This folder includes bootstrap code for the various tools included in this repository. Also
included is the packages meta-information package in `packages.ts`. This is used to read and
understand all the monorepo information (contained in the `.monorepo.json` file, and `package.json`
files across the repo).

`bootstrap-local.js` should be included when running files from this repository without compiling
first. It allows for compiling and loading packages in memory directly from the repo. Not only
does the `devkit-admin` scripts use this to include the library, but also all binaries linked
locally (like `schematics` and `ng`), when not using the npm published packages.

`istanbul-local.js` adds global hooks and information to be able to use code coverage with
`bootstrap-local.js`. Istanbul does not keep the sourcemaps properly in sync if they're available
in the code, which happens locally when transpiling TypeScript. It is currently used by the
`test` script and is included by `bootstrap-local.js` for integration.
9 changes: 9 additions & 0 deletions packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `/packages` Folder

This folder is the root of all defined packages in this repository.

Packages that are marked as `private: true` will not be published to NPM. These are limited to the
`_` subfolder.

This folder includes a directory for every scope in NPM, without the `@` sign. Then one folder
per package, which contains the `package.json`.
1 change: 0 additions & 1 deletion packages/ngtools/webpack/src/type_checker_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ export class LogMessage extends TypeCheckerMessage {
super(MESSAGE_KIND.Log);
}
}

34 changes: 30 additions & 4 deletions scripts/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const blacklist = [


function _buildRules(logger: logging.Logger) {
const tsConfigPath = path.join(__dirname, '../rules/tsconfig.json');
const tsConfigPath = path.join(__dirname, '../etc/rules/tsconfig.json');
const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);

const parsedTsConfig = ts.parseJsonConfigFileContent(
Expand All @@ -43,7 +43,7 @@ function _buildRules(logger: logging.Logger) {
}


export default function (options: ParsedArgs, logger: logging.Logger) {
export default async function (options: ParsedArgs, logger: logging.Logger) {
_buildRules(logger);

const lintOptions: ILinterOptions = {
Expand All @@ -55,6 +55,22 @@ export default function (options: ParsedArgs, logger: logging.Logger) {
const tsLintPath = path.join(__dirname, '../tslint.json');
const tsLintConfig = Configuration.loadConfigurationFromPath(tsLintPath);

// Remove comments from the configuration, ie. keys that starts with "//".
[...tsLintConfig.rules.keys()]
.filter(x => x.startsWith('//'))
.forEach(key => tsLintConfig.rules.delete(key));

// Console is used directly by tslint, and when finding a rule that doesn't exist it's considered
// a warning by TSLint but _only_ shown on the console and impossible to see through the API.
// In order to see any warnings that happen from TSLint itself, we hook into console.warn() and
// record any calls.
const oldWarn = console.warn;
let warnings = false;
console.warn = (...args) => {
warnings = true;
oldWarn(...args);
};

program.getRootFileNames().forEach(fileName => {
if (blacklist.some(x => x.test(path.relative(process.cwd(), fileName)))) {
return;
Expand All @@ -63,6 +79,8 @@ export default function (options: ParsedArgs, logger: logging.Logger) {
linter.lint(fileName, ts.sys.readFile(fileName) || '', tsLintConfig);
});

console.warn = oldWarn;

const result = linter.getResult();
const Formatter = findFormatter('codeFrame');
if (!Formatter) {
Expand All @@ -76,10 +94,18 @@ export default function (options: ParsedArgs, logger: logging.Logger) {
if (result.warningCount > 0) {
logger.info(`Warnings: ${result.warningCount}`);
}
process.exit(2);

return 2;
} else if (result.warningCount > 0) {
logger.warn(formatter.format(result.failures));
logger.info(`Warnings: ${result.warningCount}`);
process.exit(1);

return 1;
} else if (warnings) {
logger.warn('TSLint found warnings, but code is okay. See above.');

return 1;
}

return 0;
}
11 changes: 11 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `/tests` Folder

Contains all e2e tests and test assets.

## `legacy-cli/`

Contains all assets and all e2e tests from the legacy CLI repo.

## Others

Other folders contain test assets related to the Package namespace folders matching their name.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"exclude": [
"bazel-*/**/*",
"dist/**/*",
"etc/cli.angular.io",
"node_modules/**/*",
"packages/_/devkit/**/*files/**/*",
"packages/schematics/*/*/*files/**/*",
Expand Down
5 changes: 2 additions & 3 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"tslint-no-circular-imports"
],
"rulesDirectory": [
"dist/rules",
"dist/etc/rules",
"node_modules/tslint-sonarts/lib/rules"
],
"rules": {
"//03": "==================================================================================================",
"//04": "custom rules defined in dist/rules/**",
"//04": "custom rules defined in etc/rules/**",
"defocus": true,
"import-groups": true,
"no-global-tslint-disable": true,
Expand Down Expand Up @@ -86,7 +86,6 @@
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-unused-variable": [true, {"ignore-pattern": "^_"}],
"no-var-keyword": true,
"one-line": [
true,
Expand Down