Skip to content

Commit ac442ef

Browse files
committed
Correct errors found when using 'npm run lint'
1 parent ce6f729 commit ac442ef

File tree

5 files changed

+125
-125
lines changed

5 files changed

+125
-125
lines changed

src/features/completion-provider.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import { CancellationToken, TextDocument, Position, Hover } from 'vscode'
2-
import * as fs from 'fs'
3-
import * as vscode from 'vscode'
4-
import { isPositionInString, intrinsics, FORTRAN_KEYWORDS } from '../lib/helper'
5-
import { getDeclaredFunctions } from '../lib/functions'
1+
import { CancellationToken, TextDocument, Position, Hover } from 'vscode';
2+
import * as fs from 'fs';
3+
import * as vscode from 'vscode';
4+
import { isPositionInString, intrinsics, FORTRAN_KEYWORDS } from '../lib/helper';
5+
import { getDeclaredFunctions } from '../lib/functions';
66

7-
import { EXTENSION_ID } from '../lib/helper'
7+
import { EXTENSION_ID } from '../lib/helper';
88

99
class CaseCoverter {
10-
preferredCase: string
11-
static LOWER = 'lowercase'
12-
static UPPER = 'uppercase'
10+
preferredCase: string;
11+
static LOWER = 'lowercase';
12+
static UPPER = 'uppercase';
1313

1414
constructor(preferredCase: string = CaseCoverter.LOWER) {
15-
this.preferredCase = preferredCase
15+
this.preferredCase = preferredCase;
1616
}
1717

1818
convert(word: string): string {
19-
if (this.preferredCase == CaseCoverter.LOWER) {
20-
return this.toLower(word)
21-
} else if (this.preferredCase == CaseCoverter.UPPER) {
22-
return this.toUpper(word)
19+
if (this.preferredCase === CaseCoverter.LOWER) {
20+
return this.toLower(word);
21+
} else if (this.preferredCase === CaseCoverter.UPPER) {
22+
return this.toUpper(word);
2323
}
2424

25-
throw new Error(`the provided case ${this.preferredCase} is not supported`)
25+
throw new Error(`the provided case ${this.preferredCase} is not supported`);
2626
}
2727

2828
toLower(word: string) {
29-
return word.toLowerCase()
29+
return word.toLowerCase();
3030
}
3131
toUpper(word: string) {
32-
return word.toUpperCase()
32+
return word.toUpperCase();
3333
}
3434
}
3535

@@ -45,7 +45,7 @@ export class FortranCompletionProvider
4545
position,
4646
token,
4747
vscode.workspace.getConfiguration(EXTENSION_ID)
48-
)
48+
);
4949
}
5050

5151
public provideCompletionItemsInternal(
@@ -55,51 +55,51 @@ export class FortranCompletionProvider
5555
config: vscode.WorkspaceConfiguration
5656
): Thenable<vscode.CompletionItem[]> {
5757
return new Promise<vscode.CompletionItem[]>((resolve, reject) => {
58-
let lineText = document.lineAt(position.line).text
59-
let lineTillCurrentPosition = lineText.substr(0, position.character)
58+
let lineText = document.lineAt(position.line).text;
59+
let lineTillCurrentPosition = lineText.substr(0, position.character);
6060
// nothing to complete
6161
if (lineText.match(/^\s*\/\//)) {
62-
return resolve([])
62+
return resolve([]);
6363
}
6464

65-
let inString = isPositionInString(document, position)
65+
let inString = isPositionInString(document, position);
6666
if (!inString && lineTillCurrentPosition.endsWith('"')) {
6767
// completing a string
68-
return resolve([])
68+
return resolve([]);
6969
}
7070

71-
let currentWord = this.getCurrentWord(document, position)
71+
let currentWord = this.getCurrentWord(document, position);
7272

7373
if (currentWord.match(/^\d+$/)) {
7474
// starts with a number
75-
return resolve([])
75+
return resolve([]);
7676
}
7777

78-
const caseConverter = new CaseCoverter(config.get('preferredCase'))
78+
const caseConverter = new CaseCoverter(config.get('preferredCase'));
7979

8080
if (currentWord.length === 0) {
81-
resolve([])
81+
resolve([]);
8282
}
8383

8484
const intrinsicSuggestions = this.getIntrinsicSuggestions(
8585
currentWord,
8686
caseConverter
87-
)
87+
);
8888

8989
// add keyword suggestions
90-
const keywordSuggestions = this.getKeywordSuggestions(currentWord)
90+
const keywordSuggestions = this.getKeywordSuggestions(currentWord);
9191

9292
const functionSuggestions = this.getFunctionSuggestions(
9393
document,
9494
currentWord
95-
)
95+
);
9696

9797
return resolve([
9898
...intrinsicSuggestions,
9999
...keywordSuggestions,
100100
...functionSuggestions,
101-
])
102-
})
101+
]);
102+
});
103103
}
104104

105105
private getIntrinsicSuggestions(
@@ -112,8 +112,8 @@ export class FortranCompletionProvider
112112
return new vscode.CompletionItem(
113113
caseConverter.convert(intrinsic),
114114
vscode.CompletionItemKind.Method
115-
)
116-
})
115+
);
116+
});
117117
}
118118

119119
private getKeywordSuggestions(currentWord: string): vscode.CompletionItem[] {
@@ -123,37 +123,37 @@ export class FortranCompletionProvider
123123
return new vscode.CompletionItem(
124124
keyword.toLowerCase(),
125125
vscode.CompletionItemKind.Keyword
126-
)
127-
})
126+
);
127+
});
128128
}
129129

130130
private getFunctionSuggestions(
131131
document: TextDocument,
132132
currentWord: string
133133
): vscode.CompletionItem[] {
134-
const functions = getDeclaredFunctions(document)
134+
const functions = getDeclaredFunctions(document);
135135
// check for available functions
136136
return functions
137137
.filter(fun => fun.name.startsWith(currentWord))
138138
.map(fun => {
139139
return new vscode.CompletionItem(
140140
`${fun.name}(`,
141141
vscode.CompletionItemKind.Function
142-
)
143-
})
142+
);
143+
});
144144
}
145145

146146
private getCurrentWord(document: TextDocument, position: Position): string {
147-
let wordAtPosition = document.getWordRangeAtPosition(position)
148-
let currentWord = ''
147+
let wordAtPosition = document.getWordRangeAtPosition(position);
148+
let currentWord = '';
149149
if (wordAtPosition && wordAtPosition.start.character < position.character) {
150-
let word = document.getText(wordAtPosition)
150+
let word = document.getText(wordAtPosition);
151151
currentWord = word.substr(
152152
0,
153153
position.character - wordAtPosition.start.character
154-
)
154+
);
155155
}
156-
return currentWord
156+
return currentWord;
157157

158158
}
159159
}

src/lib/fortran-intrinsics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ export default [
270270
'UNPACK',
271271
'VERIFY',
272272
'XOR',
273-
]
273+
];

src/lib/helper.ts

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as fs from 'fs'
2-
import * as vscode from 'vscode'
3-
import intrinsics from './fortran-intrinsics'
4-
import { installTool } from './tools'
1+
import * as fs from 'fs';
2+
import * as vscode from 'vscode';
3+
import intrinsics from './fortran-intrinsics';
4+
import { installTool } from './tools';
55

66
// IMPORTANT: this should match the value
77
// on the package.json otherwise the extension won't
88
// work at all
9-
export const LANGUAGE_ID = 'FortranFreeForm'
10-
export const FORTRAN_FREE_FORM_ID = { language: LANGUAGE_ID, scheme: 'file' }
9+
export const LANGUAGE_ID = 'FortranFreeForm';
10+
export const FORTRAN_FREE_FORM_ID = { language: LANGUAGE_ID, scheme: 'file' };
1111
export { intrinsics }
12-
export const EXTENSION_ID = 'fortran'
12+
export const EXTENSION_ID = 'fortran';
1313

1414
export const FORTRAN_KEYWORDS = [
1515
'FUNCTION',
@@ -23,46 +23,46 @@ export const FORTRAN_KEYWORDS = [
2323
'ELIF',
2424
'END',
2525
'IMPLICIT',
26-
]
26+
];
2727

2828
export const isIntrinsic = keyword => {
2929
return (
3030
intrinsics.findIndex(intrinsic => intrinsic === keyword.toUpperCase()) !==
3131
-1
32-
)
33-
}
32+
);
33+
};
3434

3535
interface Doc {
36-
keyword: string
37-
docstr: string
36+
keyword: string;
37+
docstr: string;
3838
}
3939

4040
export const loadDocString = keyword => {
41-
keyword = keyword.toUpperCase()
42-
let filepath = __dirname + '/../docs/' + keyword + '.json'
43-
let docstr = fs.readFileSync(filepath).toString()
44-
let doc: Doc = JSON.parse(docstr)
45-
return doc.docstr
46-
}
41+
keyword = keyword.toUpperCase();
42+
let filepath = __dirname + '/../docs/' + keyword + '.json';
43+
let docstr = fs.readFileSync(filepath).toString();
44+
let doc: Doc = JSON.parse(docstr);
45+
return doc.docstr;
46+
};
4747

4848
export const _loadDocString = (keyword: string) => {
49-
keyword = keyword.toUpperCase()
49+
keyword = keyword.toUpperCase();
5050

5151
let docStringBuffer = fs.readFileSync(
5252
__dirname + '/../../../src/docs/' + keyword + '.html'
53-
)
54-
let docText = docStringBuffer.toString()
55-
const codeRegex = /<code>(.+?)<\/code>\n?/g
56-
const varRegex = /<var>(.+?)<\/var>/g
57-
const spanRegex = /<samp><span class="command">(\w+)<\/span><\/samp>/g
58-
const tableRegex = /<table\s*.*>([\s\w<>\/\W]+?)<\/table>/g
59-
const codeExampleRegex = /<code class="smallexample"[\s\W\w]*?>([\s\W\w<>]*?)<\/code>/g
60-
const headerRegex = /^ *<h(\d)>(.+?)<\/h\1>\n?/gm
61-
const defListRegex = /<dt>([\w\W]+?)<\/dt><dd>([\w\W]+?)(<br>)?<\/dd>/g
53+
);
54+
let docText = docStringBuffer.toString();
55+
const codeRegex = /<code>(.+?)<\/code>\n?/g;
56+
const varRegex = /<var>(.+?)<\/var>/g;
57+
const spanRegex = /<samp><span class="command">(\w+)<\/span><\/samp>/g;
58+
const tableRegex = /<table\s*.*>([\s\w<>\/\W]+?)<\/table>/g;
59+
const codeExampleRegex = /<code class="smallexample"[\s\W\w]*?>([\s\W\w<>]*?)<\/code>/g;
60+
const headerRegex = /^ *<h(\d)>(.+?)<\/h\1>\n?/gm;
61+
const defListRegex = /<dt>([\w\W]+?)<\/dt><dd>([\w\W]+?)(<br>)?<\/dd>/g;
6262

6363
docText = docText
6464
.replace(varRegex, (match, code: string) => {
65-
return '`' + code + '`'
65+
return '`' + code + '`';
6666
})
6767
.replace(spanRegex, (match, code) => `*${code}*`)
6868
.replace(defListRegex, (match, entry, def) => `**${entry}** ${def}\n`)
@@ -72,65 +72,65 @@ export const _loadDocString = (keyword: string) => {
7272
.replace(/<tbody\s*.*?>([\s\w<>\/\W]+?)<\/tbody>/g, (match, code) => code)
7373
.replace(tableRegex, (match, code) => code)
7474
.replace(codeRegex, (match, code: string) => {
75-
return '`' + code + '`'
75+
return '`' + code + '`';
7676
})
7777
.replace(/<p>\s*?/g, '\n')
7878
.replace(/<\/p>\s*?/g, '\n')
7979
.replace(headerRegex, (match, h: string, code: string) => {
80-
let headerLevel: number = parseInt(h)
81-
let header = '#'.repeat(headerLevel)
82-
return `${header} ${code}\n`
83-
})
84-
docText = docText.replace(/^ *<br>\n?/gm, '\n').replace(/<\?dl>/g, '')
85-
console.log(docText)
86-
return docText
87-
}
80+
let headerLevel: number = parseInt(h);
81+
let header = '#'.repeat(headerLevel);
82+
return `${header} ${code}\n`;
83+
});
84+
docText = docText.replace(/^ *<br>\n?/gm, '\n').replace(/<\?dl>/g, '');
85+
console.log(docText);
86+
return docText;
87+
};
8888

8989
export const getIncludeParams = (paths: string[]) => {
9090
if (paths.length === 0) {
91-
return ''
91+
return '';
9292
}
93-
return '-I ' + paths.join(' ')
94-
}
93+
return '-I ' + paths.join(' ');
94+
};
9595

9696
export function isPositionInString(
9797
document: vscode.TextDocument,
9898
position: vscode.Position
9999
): boolean {
100-
let lineText = document.lineAt(position.line).text
101-
let lineTillCurrentPosition = lineText.substr(0, position.character)
100+
let lineText = document.lineAt(position.line).text;
101+
let lineTillCurrentPosition = lineText.substr(0, position.character);
102102

103103
// Count the number of double quotes in the line till current position. Ignore escaped double quotes
104-
let doubleQuotesCnt = (lineTillCurrentPosition.match(/\"/g) || []).length
104+
let doubleQuotesCnt = (lineTillCurrentPosition.match(/\"/g) || []).length;
105105
let escapedDoubleQuotesCnt = (lineTillCurrentPosition.match(/\\\"/g) || [])
106-
.length
106+
.length;
107107

108-
doubleQuotesCnt -= escapedDoubleQuotesCnt
109-
return doubleQuotesCnt % 2 === 1
108+
doubleQuotesCnt -= escapedDoubleQuotesCnt;
109+
return doubleQuotesCnt % 2 === 1;
110110
}
111111

112112
let saveKeywordToJson = keyword => {
113-
let doc = _loadDocString(keyword)
114-
let docObject = JSON.stringify({ keyword: keyword, docstr: doc })
113+
let doc = _loadDocString(keyword);
114+
let docObject = JSON.stringify({ keyword: keyword, docstr: doc });
115115
fs.appendFile('src/docs/' + keyword + '.json', docObject, function(err) {
116-
if (err) throw err
117-
console.log('Saved!')
118-
})
119-
}
116+
if (err) throw err;
117+
console.log('Saved!');
118+
});
119+
};
120120

121121
export { default as getBinPath } from './paths'
122122

123123
export function promptForMissingTool(tool: string) {
124-
const items = ['Install']
125-
let message = ''
124+
const items = ['Install'];
125+
let message = '';
126126
if (tool === 'fortran-langserver') {
127127
message =
128-
'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it'
128+
'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it';
129129
}
130130
vscode.window.showInformationMessage(message, ...items).then(selected => {
131131
if (selected === 'Install') {
132-
installTool(tool)
132+
installTool(tool);
133133
}
134-
})
134+
});
135135

136136
}

0 commit comments

Comments
 (0)