Skip to content

Commit c2b8ca4

Browse files
sis0k0NathanWalker
authored andcommitted
style(eslint): CI linting, fix code style errors (#104)
- Add eslint configs and travis before_install hook for linting. - Fix code style errors to follow the NativeScript coding conventions
1 parent 15b9695 commit c2b8ca4

File tree

8 files changed

+161
-89
lines changed

8 files changed

+161
-89
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
app/node_modules/*

.eslintrc.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module.exports = {
2+
"parserOptions": {
3+
"ecmaVersion": 6
4+
},
5+
"env": {
6+
"node": true
7+
},
8+
"extends": "eslint:recommended",
9+
"rules": {
10+
"indent": [
11+
"error",
12+
4
13+
],
14+
"quotes": [
15+
"error",
16+
"double",
17+
{ "allowTemplateLiterals": true }
18+
],
19+
"semi": [
20+
"error",
21+
"always"
22+
],
23+
"yoda": [
24+
"error",
25+
"never",
26+
{ "exceptRange": true }
27+
],
28+
"key-spacing": [
29+
"error",
30+
{ "afterColon": true }
31+
],
32+
"semi-spacing": [
33+
"error",
34+
{"before": false, "after": true}
35+
],
36+
"space-infix-ops": ["error", {"int32Hint": false}],
37+
"space-before-blocks": "error",
38+
"operator-linebreak": "error",
39+
"keyword-spacing": "error",
40+
"no-trailing-spaces": "error",
41+
"brace-style": "error",
42+
"camelcase": "error",
43+
"eqeqeq": "error",
44+
"no-with": "error",
45+
"array-callback-return": "error",
46+
"curly": "error",
47+
"no-eval": "error",
48+
"no-console": "off"
49+
}
50+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.css
22
!font-awesome.css
33
*.js
4+
!.eslintrc.js
45
*.map
56
/platforms
67
node_modules

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ cache:
66
directories:
77
- .nvm
88

9+
before_install:
10+
- ./scripts/travis/lint.sh
11+
912
install:
1013
- ./scripts/travis/install.sh
1114

1215
script:
1316
- ./scripts/travis/build.sh
14-
- ./scripts/travis/test.sh
17+
- ./scripts/travis/test.sh

scripts/builder.js

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
************************************************************************************/
66
"use strict";
77

8-
var fs = require('fs');
9-
var path = require('path');
10-
var sass = require('node-sass');
11-
var glob = require('glob');
8+
var fs = require("fs");
9+
var sass = require("node-sass");
10+
var glob = require("glob");
1211

1312
// Kill The original folder, so that way it is a clean folder
14-
if (fs.existsSync('nativescript-theme-core')) {
15-
deleteFolderRecursive('nativescript-theme-core');
13+
if (fs.existsSync("nativescript-theme-core")) {
14+
deleteFolderRecursive("nativescript-theme-core");
1615
}
1716
fs.mkdirSync("nativescript-theme-core");
1817
fs.mkdirSync("nativescript-theme-core/css");
@@ -55,21 +54,25 @@ console.log("Change to the 'nativescript-theme-core' folder and you can now do y
5554
* Copy any fonts files over
5655
*/
5756
function copyFonts() {
58-
var ttfFiles = glob.sync('./app/fonts/*.ttf');
59-
var otfFiles = glob.sync('./app/fonts/*.otf');
57+
var ttfFiles = glob.sync("./app/fonts/*.ttf");
58+
var otfFiles = glob.sync("./app/fonts/*.otf");
6059
var i, out;
6160

62-
for (i=0;i<ttfFiles.length;i++) {
63-
out = ttfFiles[i].replace('./app/', './nativescript-theme-core/');
61+
for (i = 0; i < ttfFiles.length; i++) {
62+
out = ttfFiles[i].replace("./app/", "./nativescript-theme-core/");
6463
// Skip font Awesome
65-
if (out.indexOf('fontawesome') !== -1) { continue; }
64+
if (out.indexOf("fontawesome") !== -1) {
65+
continue;
66+
}
6667
fs.writeFileSync(out, fs.readFileSync(ttfFiles[i]));
6768
}
6869

69-
for (i=0;i<otfFiles.length;i++) {
70-
out = otfFiles[i].replace('./app/', './nativescript-theme-core/');
70+
for (i = 0; i < otfFiles.length; i++) {
71+
out = otfFiles[i].replace("./app/", "./nativescript-theme-core/");
7172
// Skip font Awesome
72-
if (out.indexOf('fontawesome') !== -1) { continue; }
73+
if (out.indexOf("fontawesome") !== -1) {
74+
continue;
75+
}
7376
fs.writeFileSync(out, fs.readFileSync(otfFiles[i]));
7477
}
7578

@@ -83,34 +86,34 @@ function copyFonts() {
8386
* Copy our SCSS files over
8487
*/
8588
function copySCSS() {
86-
var sassFilesPath = './app/**/*.scss';
89+
var sassFilesPath = "./app/**/*.scss";
8790
var sassFiles = glob.sync(sassFilesPath).filter(function (filePath) {
88-
return filePath.indexOf("App_Resources") === -1 && filePath.indexOf('demo-styles') === -1;
91+
return filePath.indexOf("App_Resources") === -1 && filePath.indexOf("demo-styles") === -1;
8992
});
9093

91-
for (var i=0;i<sassFiles.length;i++) {
92-
var out = sassFiles[i].replace('./app/', './nativescript-theme-core/');
94+
for (var i = 0; i < sassFiles.length; i++) {
95+
var out = sassFiles[i].replace("./app/", "./nativescript-theme-core/");
9396

94-
var paths = sassFiles[i].split('/');
95-
// eliminate the ['.' and 'app']
97+
var paths = sassFiles[i].split("/");
98+
// eliminate the ["." and "app"]
9699
paths.shift();
97100
paths.shift();
98101

99102
if (paths.length > 1) {
100-
var path = './nativescript-theme-core';
101-
for (var j=0;j<paths.length-1;j++) {
102-
path += '/' + paths[j];
103+
var path = "./nativescript-theme-core";
104+
for (var j = 0; j < paths.length - 1; j++) {
105+
path += "/" + paths[j];
103106
if (!fs.existsSync(path)) {
104107
fs.mkdirSync(path);
105108
}
106109
}
107110
}
108111

109-
if (sassFiles[i].indexOf('./app/core.') > -1) {
112+
if (sassFiles[i].indexOf("./app/core.") > -1) {
110113
// print correct version on main files
111-
var scss = fs.readFileSync(sassFiles[i], { encoding: 'utf8' });
114+
var scss = fs.readFileSync(sassFiles[i], { encoding: "utf8" });
112115
scss = printVersion(scss);
113-
fs.writeFileSync(out, scss, 'utf8');
116+
fs.writeFileSync(out, scss, "utf8");
114117
} else {
115118
fs.writeFileSync(out, fs.readFileSync(sassFiles[i]));
116119
}
@@ -124,23 +127,23 @@ function copySCSS() {
124127
*/
125128
function createCSSFromSCSS() {
126129

127-
var sassFilesPath = './app/**/*.scss';
130+
var sassFilesPath = "./app/**/*.scss";
128131
var sassImportPaths = [
129-
'./app/',
130-
'./node_modules/'
132+
"./app/",
133+
"./node_modules/"
131134
];
132135

133136
var sassFiles = glob.sync(sassFilesPath).filter(function (filePath) {
134137
var path = filePath;
135-
var parts = path.split('/');
138+
var parts = path.split("/");
136139
var filename = parts[parts.length - 1];
137-
return path.indexOf("App_Resources") === -1 && path.indexOf('demo-styles') === -1 && filename.indexOf("_") !== 0 && filename.indexOf('app.') !== 0;
140+
return path.indexOf("App_Resources") === -1 && path.indexOf("demo-styles") === -1 && filename.indexOf("_") !== 0 && filename.indexOf("app.") !== 0;
138141
});
139142

140143

141144
for (var i = 0; i < sassFiles.length; i++) {
142145
// We only process open /core. files
143-
if (sassFiles[i].indexOf('/core.') === -1) {
146+
if (sassFiles[i].indexOf("/core.") === -1) {
144147
continue;
145148
}
146149
parseSass(sassFiles[i], sassImportPaths);
@@ -153,18 +156,18 @@ function createCSSFromSCSS() {
153156
* @param importPaths - Other import paths
154157
*/
155158
function parseSass(sassFile, importPaths) {
156-
var sassFileContent = fs.readFileSync(sassFile, { encoding: 'utf8'});
157-
var outputFile = 'nativescript-theme-core/css';
158-
var offset = sassFile.lastIndexOf('/');
159+
var sassFileContent = fs.readFileSync(sassFile, { encoding: "utf8"});
160+
var outputFile = "nativescript-theme-core/css";
161+
var offset = sassFile.lastIndexOf("/");
159162
outputFile += sassFile.substring(offset);
160-
var cssFilePath = outputFile.replace('.scss', '.css');
163+
var cssFilePath = outputFile.replace(".scss", ".css");
161164

162165
// var output = sass.renderSync({
163-
var output = sass.render({
166+
sass.render({
164167
data: sassFileContent,
165168
includePaths: importPaths,
166169
outFile: cssFilePath,
167-
outputStyle: 'compressed'
170+
outputStyle: "compressed"
168171
}, function (error, result) {
169172
if (error) {
170173
console.log(error.status);
@@ -177,7 +180,7 @@ function parseSass(sassFile, importPaths) {
177180
css = printVersion(css);
178181
// uncomment to debug builds
179182
// console.log(css);
180-
fs.writeFileSync(cssFilePath, css, 'utf8');
183+
fs.writeFileSync(cssFilePath, css, "utf8");
181184

182185
// if build stats are ever desired
183186
// console.log(result.stats);
@@ -193,11 +196,11 @@ function parseSass(sassFile, importPaths) {
193196
*/
194197
function deleteFolderRecursive(path) {
195198
var files = [];
196-
if( fs.existsSync(path) ) {
199+
if ( fs.existsSync(path) ) {
197200
files = fs.readdirSync(path);
198-
files.forEach(function(file,index){
201+
files.forEach(function(file) {
199202
var curPath = path + "/" + file;
200-
if(fs.lstatSync(curPath).isDirectory()) { // recurse
203+
if (fs.lstatSync(curPath).isDirectory()) { // recurse
201204
deleteFolderRecursive(curPath);
202205
} else { // delete file
203206
fs.unlinkSync(curPath);
@@ -220,13 +223,13 @@ function copyFile(src, dest) {
220223
* Print correct version
221224
*/
222225
function printVersion(css) {
223-
return css.replace(versionPlaceholder, 'v' + version);
226+
return css.replace(versionPlaceholder, "v" + version);
224227
}
225228

226229
/**
227230
* Get version from package
228231
*/
229232
function getVersion() {
230-
var packageJSON = require('../package.json');
233+
var packageJSON = require("../package.json");
231234
return packageJSON ? packageJSON.version : null;
232235
}

scripts/postinstall.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"use strict";
77

88
// Simple require statements, built into node
9-
var fs = require('fs');
10-
var path = require('path');
11-
var os = require('os');
9+
var fs = require("fs");
10+
var path = require("path");
11+
var os = require("os");
1212

1313
// Check for the Buggy TNS Behavior...
1414
checkIfTNSBug();
@@ -17,15 +17,15 @@ checkIfTNSBug();
1717
var hasSCSS = false;
1818

1919
// Get our Paths
20-
var cwd = process.cwd() + '/';
21-
var primaryDir = path.normalize(cwd+"../../");
22-
var appDir = primaryDir + 'app/';
20+
var cwd = process.cwd() + "/";
21+
var primaryDir = path.normalize(cwd + "../../");
22+
var appDir = primaryDir + "app/";
2323

2424
// Test for has SCSS support
2525
try {
2626
var data = require(primaryDir + "package.json");
2727

28-
if (data && (data.devDependencies && data.devDependencies['nativescript-dev-sass']) || (data.dependencies && data.dependencies['nativescript-dev-sass']) ) {
28+
if (data && (data.devDependencies && data.devDependencies["nativescript-dev-sass"]) || (data.dependencies && data.dependencies["nativescript-dev-sass"]) ) {
2929
hasSCSS = true;
3030
}
3131
} catch (err) {
@@ -38,7 +38,7 @@ try {
3838
// ------------------------------------------------------
3939

4040
// Create our CSS folder
41-
copyFolder(cwd+"css", appDir+"css");
41+
copyFolder(cwd + "css", appDir + "css");
4242

4343
// Update our main app.css to import the light theme if another theme is not already imported
4444
var appSheetPath = appDir + "app.css";
@@ -61,7 +61,7 @@ copyFolder(cwd + "fonts", appDir + "fonts");
6161
// ------------------------------------------------------
6262

6363
if (hasSCSS) {
64-
copyFolder(cwd+"theme-core-scss", appDir+"theme-core-scss");
64+
copyFolder(cwd + "theme-core-scss", appDir + "theme-core-scss");
6565
copyFile(cwd, appDir, "_bootstrap-map.scss");
6666
copyFile(cwd, appDir, "core.dark.android.scss");
6767
copyFile(cwd, appDir, "core.dark.ios.scss");
@@ -98,12 +98,14 @@ function themeImported(sheetPath, themeBasePath) {
9898
*/
9999
function copyFolder(src, dest) {
100100
// No source Folder exists, can't copy it!
101-
if (!fs.existsSync(src)) { return false; }
101+
if (!fs.existsSync(src)) {
102+
return false;
103+
}
102104

103105
var files = fs.readdirSync(src);
104-
files.forEach(function(file){
106+
files.forEach(function(file) {
105107
var curPath = src + "/" + file;
106-
if(fs.lstatSync(curPath).isDirectory()) { // check to see if we need to recurse
108+
if (fs.lstatSync(curPath).isDirectory()) { // check to see if we need to recurse
107109
copyFolder(curPath, dest + "/" + file);
108110
} else { // copy file
109111
copyFile(src, dest, file);
@@ -122,19 +124,21 @@ function copyFile(src, dest, file) {
122124
if (!fs.existsSync(dest)) {
123125
mkRecursiveDirectories(dest);
124126
}
125-
fs.writeFileSync(dest+"/"+file, fs.readFileSync(src + "/" + file));
127+
fs.writeFileSync(dest + "/" + file, fs.readFileSync(src + "/" + file));
126128
}
127129

128130
/**
129131
* This creates a recursive folder structure
130132
* @param path
131133
*/
132134
function mkRecursiveDirectories(path) {
133-
var data = path.replace('\\','/').split('/');
134-
var newPath = '';
135-
for (var i=0;i<data.length;i++) {
135+
var data = path.replace("\\","/").split("/");
136+
var newPath = "";
137+
for (var i = 0; i < data.length; i++) {
136138
newPath += data[i] + "/";
137-
if (fs.existsSync(newPath)) { continue; }
139+
if (fs.existsSync(newPath)) {
140+
continue;
141+
}
138142
fs.mkdirSync(newPath);
139143
}
140144
}
@@ -163,7 +167,7 @@ function checkIfTNSBug() {
163167

164168
// Mac Directory
165169
env = process.env["TMPDIR"];
166-
if (env && (process.argv[1].indexOf(env) === 0 || process.argv[1].indexOf("/private"+env) === 0)) {
170+
if (env && (process.argv[1].indexOf(env) === 0 || process.argv[1].indexOf("/private" + env) === 0)) {
167171
process.exit(0);
168172
}
169173
}

scripts/travis/lint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
npm install -g eslint
6+
eslint .

0 commit comments

Comments
 (0)