Skip to content

Commit 8f43d12

Browse files
authored
feat: add eslint w/ lint fixes (#151)
* chore(dev-dep): added @cordova/eslint-config at 6.0.1 * chore(lint): apply lint auto-corrections * test(lint): PBXFile constructor name to start with uppercase * test(lint): PBXProject constructor name to start with uppercase * test(lint): update more constructor name to start with uppercase * chore(lint): variable cleanup in test dir * remove unused variables * remove unnecessary variable declarations * removed variable redeclarations * use const or let where appropriate * remove unnecessary require statements * split delimited variables into separate lines * chore(lint): remove unused methods in test dir * chore(lint): use path.join instead of string concatenation * chore(lint): inline disable no-template-curly-in-string * chore(lint): remove unnecessary read for buildPhase after addBuildPhase * chore(lint): remove unnecessary variable * chore(lint): resolve no-prototype-builtins * chore(lint): resolve eqeqeq & spacing * chore(lint): resolve eqeqeq & unused variables in lib/pbxWriter * chore(lint): resolve lint errors in lib/pbxFile * chore(lint): uppercase PBXProject in lib/pbxProject.js * chore(lint): uppercase PBXFile & PBXWriter in lib/pbxProject.js * chore(lint): resolve eqeqeq in lib/pbxProject.js * chore(lint): cleanup loops in lib/pbxProject.js * chore(lint): resolve no-unused-vars in lib/pbxProject.js * chore(lint): resolve no-var in lib/pbxProject.js * chore(lint): resolve no-undef in lib/pbxProject.js * chore(lint): resolve no-new-object in lib/pbxProject.js * chore(lint): use path.join instead of string concatenation in lib/pbxProject.js * chore(lint): resolve no-mixed-operators in lib/pbxProject.js * chore(lint): declare variable on own line
1 parent f9b58c4 commit 8f43d12

55 files changed

Lines changed: 5126 additions & 5738 deletions

Some content is hidden

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

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
.*
1919
coverage
2020
test
21+
eslint.config.js
22+
licence_checker.yml

eslint.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
const { defineConfig, globalIgnores } = require('eslint/config');
21+
const nodeConfig = require('@cordova/eslint-config/node');
22+
const nodeTestConfig = require('@cordova/eslint-config/node-tests');
23+
24+
module.exports = defineConfig([
25+
globalIgnores([
26+
'lib/parser/pbxproj.js'
27+
]),
28+
...nodeConfig,
29+
...nodeTestConfig.map(config => ({
30+
files: ['test/**/*.js'],
31+
...config
32+
}))
33+
]);

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
under the License.
1818
*/
1919

20-
exports.project = require('./lib/pbxProject')
20+
exports.project = require('./lib/pbxProject');

lib/parseJob.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
// parsing is slow and blocking right now
2121
// so we do it in a separate process
22-
var fs = require('fs'),
23-
parser = require('./parser/pbxproj'),
24-
path = process.argv[2],
25-
fileContents, obj;
22+
const fs = require('fs');
23+
const parser = require('./parser/pbxproj');
24+
const path = process.argv[2];
25+
let fileContents;
26+
let obj;
2627

2728
try {
2829
fileContents = fs.readFileSync(path, 'utf-8');

lib/pbxFile.js

Lines changed: 97 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,77 @@
1717
under the License.
1818
*/
1919

20-
var path = require('path'),
21-
util = require('util');
22-
23-
var DEFAULT_SOURCETREE = '"<group>"',
24-
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
25-
DEFAULT_FILEENCODING = 4,
26-
DEFAULT_GROUP = 'Resources',
27-
DEFAULT_FILETYPE = 'unknown';
28-
29-
var FILETYPE_BY_EXTENSION = {
30-
a: 'archive.ar',
31-
app: 'wrapper.application',
32-
appex: 'wrapper.app-extension',
33-
bundle: 'wrapper.plug-in',
34-
dylib: 'compiled.mach-o.dylib',
35-
framework: 'wrapper.framework',
36-
h: 'sourcecode.c.h',
37-
m: 'sourcecode.c.objc',
38-
markdown: 'text',
39-
mdimporter: 'wrapper.cfbundle',
40-
octest: 'wrapper.cfbundle',
41-
pch: 'sourcecode.c.h',
42-
plist: 'text.plist.xml',
43-
sh: 'text.script.sh',
44-
swift: 'sourcecode.swift',
45-
tbd: 'sourcecode.text-based-dylib-definition',
46-
xcassets: 'folder.assetcatalog',
47-
xcconfig: 'text.xcconfig',
48-
xcdatamodel: 'wrapper.xcdatamodel',
49-
xcodeproj: 'wrapper.pb-project',
50-
xctest: 'wrapper.cfbundle',
51-
xib: 'file.xib',
52-
strings: 'text.plist.strings'
53-
},
54-
GROUP_BY_FILETYPE = {
55-
'archive.ar': 'Frameworks',
56-
'compiled.mach-o.dylib': 'Frameworks',
57-
'sourcecode.text-based-dylib-definition': 'Frameworks',
58-
'wrapper.framework': 'Frameworks',
59-
'embedded.framework': 'Embed Frameworks',
60-
'sourcecode.c.h': 'Resources',
61-
'sourcecode.c.objc': 'Sources',
62-
'sourcecode.swift': 'Sources'
63-
},
64-
PATH_BY_FILETYPE = {
65-
'compiled.mach-o.dylib': 'usr/lib/',
66-
'sourcecode.text-based-dylib-definition': 'usr/lib/',
67-
'wrapper.framework': 'System/Library/Frameworks/'
68-
},
69-
SOURCETREE_BY_FILETYPE = {
70-
'compiled.mach-o.dylib': 'SDKROOT',
71-
'sourcecode.text-based-dylib-definition': 'SDKROOT',
72-
'wrapper.framework': 'SDKROOT'
73-
},
74-
ENCODING_BY_FILETYPE = {
75-
'sourcecode.c.h': 4,
76-
'sourcecode.c.h': 4,
77-
'sourcecode.c.objc': 4,
78-
'sourcecode.swift': 4,
79-
'text': 4,
80-
'text.plist.xml': 4,
81-
'text.script.sh': 4,
82-
'text.xcconfig': 4,
83-
'text.plist.strings': 4
84-
};
85-
86-
87-
function unquoted(text){
88-
return text == null ? '' : text.replace (/(^")|("$)/g, '')
20+
const path = require('path');
21+
const util = require('util');
22+
23+
const DEFAULT_SOURCETREE = '"<group>"';
24+
const DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR';
25+
const DEFAULT_GROUP = 'Resources';
26+
const DEFAULT_FILETYPE = 'unknown';
27+
28+
const FILETYPE_BY_EXTENSION = {
29+
a: 'archive.ar',
30+
app: 'wrapper.application',
31+
appex: 'wrapper.app-extension',
32+
bundle: 'wrapper.plug-in',
33+
dylib: 'compiled.mach-o.dylib',
34+
framework: 'wrapper.framework',
35+
h: 'sourcecode.c.h',
36+
m: 'sourcecode.c.objc',
37+
markdown: 'text',
38+
mdimporter: 'wrapper.cfbundle',
39+
octest: 'wrapper.cfbundle',
40+
pch: 'sourcecode.c.h',
41+
plist: 'text.plist.xml',
42+
sh: 'text.script.sh',
43+
swift: 'sourcecode.swift',
44+
tbd: 'sourcecode.text-based-dylib-definition',
45+
xcassets: 'folder.assetcatalog',
46+
xcconfig: 'text.xcconfig',
47+
xcdatamodel: 'wrapper.xcdatamodel',
48+
xcodeproj: 'wrapper.pb-project',
49+
xctest: 'wrapper.cfbundle',
50+
xib: 'file.xib',
51+
strings: 'text.plist.strings'
52+
};
53+
const GROUP_BY_FILETYPE = {
54+
'archive.ar': 'Frameworks',
55+
'compiled.mach-o.dylib': 'Frameworks',
56+
'sourcecode.text-based-dylib-definition': 'Frameworks',
57+
'wrapper.framework': 'Frameworks',
58+
'embedded.framework': 'Embed Frameworks',
59+
'sourcecode.c.h': 'Resources',
60+
'sourcecode.c.objc': 'Sources',
61+
'sourcecode.swift': 'Sources'
62+
};
63+
const PATH_BY_FILETYPE = {
64+
'compiled.mach-o.dylib': 'usr/lib/',
65+
'sourcecode.text-based-dylib-definition': 'usr/lib/',
66+
'wrapper.framework': 'System/Library/Frameworks/'
67+
};
68+
const SOURCETREE_BY_FILETYPE = {
69+
'compiled.mach-o.dylib': 'SDKROOT',
70+
'sourcecode.text-based-dylib-definition': 'SDKROOT',
71+
'wrapper.framework': 'SDKROOT'
72+
};
73+
const ENCODING_BY_FILETYPE = {
74+
'sourcecode.c.h': 4,
75+
'sourcecode.c.objc': 4,
76+
'sourcecode.swift': 4,
77+
text: 4,
78+
'text.plist.xml': 4,
79+
'text.script.sh': 4,
80+
'text.xcconfig': 4,
81+
'text.plist.strings': 4
82+
};
83+
84+
function unquoted (text) {
85+
return text == null ? '' : text.replace(/(^")|("$)/g, '');
8986
}
9087

91-
function detectType(filePath) {
92-
var extension = path.extname(filePath).substring(1),
93-
filetype = FILETYPE_BY_EXTENSION[unquoted(extension)];
88+
function detectType (filePath) {
89+
const extension = path.extname(filePath).substring(1);
90+
const filetype = FILETYPE_BY_EXTENSION[unquoted(extension)];
9491

9592
if (!filetype) {
9693
return DEFAULT_FILETYPE;
@@ -99,31 +96,31 @@ function detectType(filePath) {
9996
return filetype;
10097
}
10198

102-
function defaultExtension(fileRef) {
103-
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
104-
fileRef.lastKnownFileType : fileRef.explicitFileType;
99+
function defaultExtension (fileRef) {
100+
const filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType !== DEFAULT_FILETYPE
101+
? fileRef.lastKnownFileType
102+
: fileRef.explicitFileType;
105103

106-
for(var extension in FILETYPE_BY_EXTENSION) {
107-
if(FILETYPE_BY_EXTENSION.hasOwnProperty(unquoted(extension)) ) {
108-
if(FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype) )
109-
return extension;
104+
for (const extension in FILETYPE_BY_EXTENSION) {
105+
if (Object.prototype.hasOwnProperty.call(FILETYPE_BY_EXTENSION, unquoted(extension))) {
106+
if (FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype)) { return extension; }
110107
}
111108
}
112109
}
113110

114-
function defaultEncoding(fileRef) {
115-
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
116-
encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
111+
function defaultEncoding (fileRef) {
112+
const filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
113+
const encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
117114

118115
if (encoding) {
119116
return encoding;
120117
}
121118
}
122119

123-
function detectGroup(fileRef, opt) {
124-
var extension = path.extname(fileRef.basename).substring(1),
125-
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
126-
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
120+
function detectGroup (fileRef, opt) {
121+
const extension = path.extname(fileRef.basename).substring(1);
122+
const filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
123+
const groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
127124

128125
if (extension === 'xcdatamodeld') {
129126
return 'Sources';
@@ -140,10 +137,9 @@ function detectGroup(fileRef, opt) {
140137
return groupName;
141138
}
142139

143-
function detectSourcetree(fileRef) {
144-
145-
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
146-
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
140+
function detectSourcetree (fileRef) {
141+
const filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
142+
const sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
147143

148144
if (fileRef.explicitFileType) {
149145
return DEFAULT_PRODUCT_SOURCETREE;
@@ -160,9 +156,9 @@ function detectSourcetree(fileRef) {
160156
return sourcetree;
161157
}
162158

163-
function defaultPath(fileRef, filePath) {
164-
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
165-
defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
159+
function defaultPath (fileRef, filePath) {
160+
const filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
161+
const defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
166162

167163
if (fileRef.customFramework) {
168164
return filePath;
@@ -175,25 +171,15 @@ function defaultPath(fileRef, filePath) {
175171
return filePath;
176172
}
177173

178-
function defaultGroup(fileRef) {
179-
var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType];
180-
181-
if (!groupName) {
182-
return DEFAULT_GROUP;
183-
}
184-
185-
return defaultGroup;
186-
}
187-
188-
function pbxFile(filepath, opt) {
189-
var opt = opt || {};
174+
function pbxFile (filepath, opt) {
175+
opt = opt || {};
190176

191177
this.basename = path.basename(filepath);
192178
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
193179
this.group = detectGroup(this, opt);
194180

195181
// for custom frameworks
196-
if (opt.customFramework == true) {
182+
if (opt.customFramework === true) {
197183
this.customFramework = true;
198184
this.dirname = path.dirname(filepath).replace(/\\/g, '/');
199185
}
@@ -214,21 +200,17 @@ function pbxFile(filepath, opt) {
214200
this.sourceTree = opt.sourceTree || detectSourcetree(this);
215201
this.includeInIndex = 0;
216202

217-
if (opt.weak && opt.weak === true)
218-
this.settings = { ATTRIBUTES: ['Weak'] };
203+
if (opt.weak && opt.weak === true) { this.settings = { ATTRIBUTES: ['Weak'] }; }
219204

220205
if (opt.compilerFlags) {
221-
if (!this.settings)
222-
this.settings = {};
206+
if (!this.settings) { this.settings = {}; }
223207
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
224208
}
225209

226210
if (opt.embed && opt.sign) {
227-
if (!this.settings)
228-
this.settings = {};
229-
if (!this.settings.ATTRIBUTES)
230-
this.settings.ATTRIBUTES = [];
231-
this.settings.ATTRIBUTES.push('CodeSignOnCopy');
211+
if (!this.settings) { this.settings = {}; }
212+
if (!this.settings.ATTRIBUTES) { this.settings.ATTRIBUTES = []; }
213+
this.settings.ATTRIBUTES.push('CodeSignOnCopy');
232214
}
233215
}
234216

0 commit comments

Comments
 (0)