Skip to content

Commit 8a6de14

Browse files
authored
refactor: add a linter and fix lint issues (#221)
1 parent f4a098a commit 8a6de14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1002
-848
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111
"debug": "node --debug-brk $(which ng) g command",
1212
"debug-v8": "node --inspect-brk $(which ng) g command",
1313
"debug-ng-new": "node --inspect-brk $(which ng) new -c=@nativescript/schematics projectName",
14-
"version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
14+
"version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
15+
"lint": "tslint --project ./tsconfig.json -c ./tslint.json 'src/**/*.ts'",
16+
"lint:fix": "tslint --project ./tsconfig.json -c ./tslint.json 'src/**/*.ts' --fix"
1517
},
1618
"schematics": "./src/collection.json",
1719
"dependencies": {
1820
"@angular-devkit/core": "~8.0.0",
1921
"@angular-devkit/schematics": "~8.0.0",
2022
"@nativescript/tslint-rules": "~0.0.1",
2123
"@phenomnomnominal/tsquery": "^3.0.0",
22-
"@schematics/angular": "~8.0.0",
23-
"tslint": "^5.16.0"
24+
"@schematics/angular": "~8.0.0"
2425
},
2526
"devDependencies": {
2627
"@types/jasmine": "^2.6.0",
2728
"@types/node": "^8.0.31",
2829
"conventional-changelog-cli": "^2.0.1",
2930
"jasmine": "^2.8.0",
3031
"jasmine-spec-reporter": "^4.2.1",
32+
"tslint": "^5.18.0",
3133
"typescript": "3.4.5"
3234
},
3335
"repository": {

src/add-ns/index.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import { Schema as ConvertRelativeImportsSchema } from '../convert-relative-impo
2727
let extensions: Extensions;
2828
let projectSettings: AngularProjectSettings;
2929

30-
export default function (options: MigrationOptions): Rule {
30+
export default function(options: MigrationOptions): Rule {
3131
extensions = {
3232
ns: (options.nsExtension.length > 0) ? '.' + options.nsExtension : '',
33-
web: (options.webExtension.length > 0) ? '.' + options.webExtension : ''
33+
web: (options.webExtension.length > 0) ? '.' + options.webExtension : '',
3434
};
3535

3636
return chain([
@@ -72,7 +72,9 @@ export default function (options: MigrationOptions): Rule {
7272
*/
7373
const validateOptions = (options: MigrationOptions) => () => {
7474
if (options.nsExtension === options.webExtension) {
75-
throw new SchematicsException(`nsExtension "${options.nsExtension}" and webExtension "${options.webExtension}" should have different values`);
75+
throw new SchematicsException(
76+
`nsExtension "${options.nsExtension}" and webExtension "${options.webExtension}" should have different values`,
77+
);
7678
}
7779
};
7880

@@ -98,10 +100,10 @@ ${JSON.stringify(angularJson.cli, null, 2)}
98100
${JSON.stringify(angularJson.cli, null, 2)}`);
99101
}
100102

101-
angularJson.cli = { 'defaultCollection': defaultCollection };
103+
angularJson.cli = { defaultCollection };
102104

103105
tree.overwrite('angular.json', JSON.stringify(angularJson, null, 2));
104-
}
106+
};
105107

106108
const addNsFiles = (options: MigrationOptions) => (_tree: Tree, context: SchematicContext) => {
107109
context.logger.info('Adding {N} files');
@@ -126,11 +128,12 @@ const addNsFiles = (options: MigrationOptions) => (_tree: Tree, context: Schemat
126128
entryComponentName: projectSettings.entryComponentName,
127129
entryComponentImportPath: projectSettings.entryComponentImportPath,
128130

129-
indexAppRootTag: projectSettings.indexAppRootTag
131+
indexAppRootTag: projectSettings.indexAppRootTag,
130132
};
131133
const templateSource = apply(url('./_ns-files'), [
132-
template(templateOptions)
134+
template(templateOptions),
133135
]);
136+
134137
return mergeWith(templateSource);
135138
};
136139

@@ -156,9 +159,10 @@ const addSampleFiles = () => (_tree: Tree, context: SchematicContext) => {
156159
const addSampleComponent = (nsExtension: string, webExtension: string, project: string) =>
157160
(_tree, context: SchematicContext) => {
158161
context.logger.info('Adding Sample Shared Component');
162+
159163
return schematic('component', {
160-
nsExtension: nsExtension,
161-
webExtension: webExtension,
164+
nsExtension,
165+
webExtension,
162166
web: true,
163167
nativescript: true,
164168
name: 'auto-generated',
@@ -171,8 +175,9 @@ const addSampleComponent = (nsExtension: string, webExtension: string, project:
171175

172176
const addAppResources = () => (_tree: Tree, context: SchematicContext) => {
173177
context.logger.info('Adding App_Resources');
178+
174179
return schematic('app-resources', {
175-
path: ''
180+
path: '',
176181
});
177182
};
178183

@@ -195,7 +200,7 @@ const mergeGitIgnore = (tree: Tree, context: SchematicContext) => {
195200
'platforms/',
196201
'hooks/',
197202
`${projectSettings.sourceRoot}/**/*.js`,
198-
].filter(line => !gitignore.includes(line));
203+
].filter((line) => !gitignore.includes(line));
199204

200205
const nsGitignoreContent =
201206
`# NativeScript` +
@@ -207,7 +212,7 @@ const mergeGitIgnore = (tree: Tree, context: SchematicContext) => {
207212
recorder.insertLeft(0, nsGitignoreContent);
208213

209214
tree.commitUpdate(recorder);
210-
}
215+
};
211216

212217
/**
213218
* Adds {N} npm run scripts to package.json
@@ -223,24 +228,23 @@ const addRunScriptsToPackageJson = (tree: Tree, context: SchematicContext) => {
223228
android: 'tns run android --bundle',
224229
ios: 'tns run ios --bundle',
225230
mobile: 'tns run --bundle',
226-
preview: 'tns preview --bundle'
231+
preview: 'tns preview --bundle',
227232
};
228-
packageJson.scripts = Object.assign({}, scriptsToAdd, packageJson.scripts);
233+
packageJson.scripts = {...scriptsToAdd, ...packageJson.scripts};
229234

230235
overwritePackageJson(tree, packageJson);
231-
}
236+
};
232237

233238
const addNativeScriptProjectId = (tree: Tree, context: SchematicContext) => {
234239
context.logger.info('Adding NativeScript Project ID to package.json');
235240
const packageJson: any = getJsonFile(tree, 'package.json');
236241

237242
packageJson.nativescript = packageJson.nativescript || {};
238-
packageJson.nativescript = Object.assign({
239-
id: 'org.nativescript.ngsample'
240-
}, packageJson.nativescript);
243+
packageJson.nativescript = {
244+
id: 'org.nativescript.ngsample', ...packageJson.nativescript};
241245

242246
tree.overwrite('package.json', JSON.stringify(packageJson, null, 2));
243-
}
247+
};
244248

245249
/**
246250
* Add web-specific path mappings and files
@@ -264,42 +268,42 @@ const modifyWebTsconfig = (tree: Tree, context: SchematicContext) => {
264268

265269
// paths
266270
const webPaths = {
267-
"@src/*": [
271+
'@src/*': [
268272
`${srcDir}/*.web`,
269-
`${srcDir}/*`]
273+
`${srcDir}/*`],
270274
};
271275
tsConfig.compilerOptions = tsConfig.compilerOptions || {};
272276
tsConfig.compilerOptions.paths = {
273277
...tsConfig.compilerOptions.paths,
274-
...webPaths
275-
}
278+
...webPaths,
279+
};
276280

277281
tree.overwrite(tsConfigPath, JSON.stringify(tsConfig, null, 2));
278282

279283
if (!tsConfig.extends) {
280-
return
284+
return;
281285
}
282286

283287
const baseTsConfigPath = join(dirname(tsConfigPath), tsConfig.extends);
284288
const baseTsConfig: any = getJsonFile(tree, baseTsConfigPath);
285289

286290
const basePaths = {
287-
"@src/*": [
291+
'@src/*': [
288292
`${srcDir}/*.android.ts`,
289293
`${srcDir}/*.ios.ts`,
290294
`${srcDir}/*.tns.ts`,
291295
`${srcDir}/*.web.ts`,
292-
`${srcDir}/*`]
296+
`${srcDir}/*`],
293297
};
294298

295299
baseTsConfig.compilerOptions = baseTsConfig.compilerOptions || {};
296300
baseTsConfig.compilerOptions.paths = {
297301
...baseTsConfig.compilerOptions.paths,
298-
...basePaths
299-
}
302+
...basePaths,
303+
};
300304

301305
tree.overwrite(baseTsConfigPath, JSON.stringify(baseTsConfig, null, 2));
302-
}
306+
};
303307

304308
const addDependencies = () => (tree: Tree, context: SchematicContext) => {
305309
context.logger.info('Adding npm dependencies');
@@ -310,15 +314,15 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
310314
'nativescript-angular': '~8.0.1',
311315
'nativescript-theme-core': '~1.0.4',
312316
'reflect-metadata': '~0.1.12',
313-
'tns-core-modules': '~5.4.0'
317+
'tns-core-modules': '~5.4.0',
314318
};
315-
packageJson.dependencies = Object.assign({}, depsToAdd, packageJson.dependencies);
319+
packageJson.dependencies = {...depsToAdd, ...packageJson.dependencies};
316320

317321
const devDepsToAdd = {
318322
'nativescript-dev-webpack': '~0.24.0',
319323
'@nativescript/schematics': '~0.6.0',
320324
};
321-
packageJson.devDependencies = Object.assign({}, devDepsToAdd, packageJson.devDependencies);
325+
packageJson.devDependencies = {...devDepsToAdd, ...packageJson.devDependencies};
322326

323327
overwritePackageJson(tree, packageJson);
324-
}
328+
};

src/add-ns/index_spec.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ describe('Add {N} schematic', () => {
1717
nsExtension: 'tns',
1818
webExtension: '',
1919
sample: false,
20-
skipAutoGeneratedComponent: false
20+
skipAutoGeneratedComponent: false,
2121
};
2222

2323
let appTree: UnitTestTree;
2424

2525
beforeEach(async () => {
26-
appTree = new UnitTestTree(new HostTree);
26+
appTree = new UnitTestTree(new HostTree());
2727
appTree = await setupProject(appTree, schematicRunner, project);
2828
});
2929

@@ -93,8 +93,8 @@ describe('Add {N} schematic', () => {
9393
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
9494
const { scripts } = packageJson;
9595
expect(scripts).toBeDefined();
96-
expect(scripts['android']).toEqual('tns run android --bundle');
97-
expect(scripts['ios']).toEqual('tns run ios --bundle');
96+
expect(scripts.android).toEqual('tns run android --bundle');
97+
expect(scripts.ios).toEqual('tns run ios --bundle');
9898
});
9999

100100
it('should add NativeScript key to the package json', () => {
@@ -105,7 +105,7 @@ describe('Add {N} schematic', () => {
105105
const { nativescript } = packageJson;
106106

107107
expect(nativescript).toBeDefined();
108-
expect(nativescript['id']).toEqual('org.nativescript.ngsample');
108+
expect(nativescript.id).toEqual('org.nativescript.ngsample');
109109
});
110110

111111
it('should modify the tsconfig.app.json (web) to include files and path mappings', () => {
@@ -121,11 +121,11 @@ describe('Add {N} schematic', () => {
121121

122122
const paths = webTsconfig.compilerOptions.paths;
123123
expect(paths).toBeDefined();
124-
expect(paths["@src/*"]).toBeDefined();
124+
expect(paths['@src/*']).toBeDefined();
125125

126-
const maps = paths["@src/*"];
127-
expect(maps).toContain("src/*.web");
128-
expect(maps).toContain("src/*");
126+
const maps = paths['@src/*'];
127+
expect(maps).toContain('src/*.web');
128+
expect(maps).toContain('src/*');
129129
});
130130

131131
it('should create the tsconfig.tns.json with files and path mappings', () => {
@@ -140,13 +140,13 @@ describe('Add {N} schematic', () => {
140140

141141
const paths = nsTsConfig.compilerOptions.paths;
142142
expect(paths).toBeDefined();
143-
expect(paths["@src/*"]).toBeDefined();
143+
expect(paths['@src/*']).toBeDefined();
144144

145-
const maps = paths["@src/*"];
146-
expect(maps).toContain("src/*.ios.ts");
147-
expect(maps).toContain("src/*.android.ts");
148-
expect(maps).toContain("src/*.tns.ts");
149-
expect(maps).toContain("src/*.ts");
145+
const maps = paths['@src/*'];
146+
expect(maps).toContain('src/*.ios.ts');
147+
expect(maps).toContain('src/*.android.ts');
148+
expect(maps).toContain('src/*.tns.ts');
149+
expect(maps).toContain('src/*.ts');
150150
});
151151

152152
it('should modify the base tsconfig.json to include path mappings', () => {
@@ -157,14 +157,14 @@ describe('Add {N} schematic', () => {
157157

158158
const paths = baseTsConfig.compilerOptions.paths;
159159
expect(paths).toBeDefined();
160-
expect(paths["@src/*"]).toBeDefined();
161-
162-
const maps = paths["@src/*"];
163-
expect(maps).toContain("src/*.android.ts");
164-
expect(maps).toContain("src/*.ios.ts");
165-
expect(maps).toContain("src/*.tns.ts");
166-
expect(maps).toContain("src/*.web.ts");
167-
expect(maps).toContain("src/*");
160+
expect(paths['@src/*']).toBeDefined();
161+
162+
const maps = paths['@src/*'];
163+
expect(maps).toContain('src/*.android.ts');
164+
expect(maps).toContain('src/*.ios.ts');
165+
expect(maps).toContain('src/*.tns.ts');
166+
expect(maps).toContain('src/*.web.ts');
167+
expect(maps).toContain('src/*');
168168
});
169169

170170
it('should generate a sample shared component', () => {
@@ -175,13 +175,13 @@ describe('Add {N} schematic', () => {
175175
expect(files).toContain('/src/app/auto-generated/auto-generated.component.html');
176176
expect(files).toContain('/src/app/auto-generated/auto-generated.component.tns.html');
177177
expect(appRoutingModuleContent).toMatch(
178-
/import { AutoGeneratedComponent } from '@src\/app\/auto-generated\/auto-generated.component'/
178+
/import { AutoGeneratedComponent } from '@src\/app\/auto-generated\/auto-generated.component'/,
179179
);
180180
expect(appRoutingModuleContent).toMatch(
181-
/{\s+path: 'auto-generated',\s+component: AutoGeneratedComponent,\s+},/g
181+
/{\s+path: 'auto-generated',\s+component: AutoGeneratedComponent,\s+},/g,
182182
);
183183
expect(appComponentTemplate).not.toContain(
184-
'<Label text="Entry Component works" textWrap="true"></Label>'
184+
'<Label text="Entry Component works" textWrap="true"></Label>',
185185
);
186186
});
187187
});
@@ -204,13 +204,13 @@ describe('Add {N} schematic', () => {
204204
expect(files).not.toContain('/src/app/auto-generated/auto-generated.component.html');
205205
expect(files).not.toContain('/src/app/auto-generated/auto-generated.component.ts');
206206
expect(appRoutingModuleContent).not.toMatch(
207-
/import { AutoGeneratedComponent } from '.\/auto-generated\/auto-generated.component'/
207+
/import { AutoGeneratedComponent } from '.\/auto-generated\/auto-generated.component'/,
208208
);
209209
expect(appRoutingModuleContent).toContain(
210-
'export const routes: Routes = []'
210+
'export const routes: Routes = []',
211211
);
212212
expect(appComponentTemplate).toContain(
213-
'<Label text="Entry Component works" textWrap="true"></Label>'
213+
'<Label text="Entry Component works" textWrap="true"></Label>',
214214
);
215215
});
216216
});
@@ -246,7 +246,7 @@ describe('Add {N} schematic', () => {
246246
it('should configure routing for redirection', () => {
247247
const appRoutingModuleContent = appTree.readContent('/src/app/app-routing.module.tns.ts');
248248
expect(appRoutingModuleContent).toMatch(
249-
/{\s+path: '',\s+redirectTo: '\/players',\s+pathMatch: 'full',\s+},/g
249+
/{\s+path: '',\s+redirectTo: '\/players',\s+pathMatch: 'full',\s+},/g,
250250
);
251251
});
252252
});
@@ -264,18 +264,18 @@ async function setupProject(
264264
{
265265
name: 'workspace',
266266
version: '8.0.0',
267-
newProjectRoot: ''
268-
}
267+
newProjectRoot: '',
268+
},
269269
).toPromise();
270270

271271
tree = await schematicRunner.runExternalSchematicAsync(
272272
'@schematics/angular',
273273
'application',
274274
{
275275
name,
276-
projectRoot: ''
276+
projectRoot: '',
277277
},
278-
tree
278+
tree,
279279
).toPromise();
280280

281281
return tree;

src/add-ns/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Schema {
99
webExtension: string;
1010
/**
1111
* The name of the project to be converted to a code sharing structure
12-
* The default option is the smart default 'projectName' provided by the Angular CLI.
12+
* The default option is the smart default 'projectName' provided by the Angular CLI.
1313
*/
1414
project: string;
1515
/**

0 commit comments

Comments
 (0)