Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: Warning when import from http
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 3, 2020
1 parent 8e7bf88 commit 72d9db3
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ connection.onCompletion(async params => {
return [];
}

console.log(context);

const config = await getWorkspaceConfig(doc.uri);

if (!config.enable) {
Expand Down Expand Up @@ -310,7 +308,7 @@ async function validator(document: TextDocument) {
".wasm": true
};

const diagnostics: Diagnostic[] = moduleNodes
const invalidImportModulesDiagnostics: Diagnostic[] = moduleNodes
.map(moduleNode => {
const [extensionName] = moduleNode.text.match(extensionNameReg) || [];

Expand All @@ -331,10 +329,35 @@ async function validator(document: TextDocument) {
})
.filter(v => v);

const NotHTTPSImportModulesDiagnostics: Diagnostic[] = moduleNodes
.map(moduleNode => {
if (/^https?:\/\//.test(moduleNode.text)) {
if (/^https:\/\//.test(moduleNode.text) === false) {
const range = Range.create(
document.positionAt(moduleNode.pos),
document.positionAt(moduleNode.end)
);

return Diagnostic.create(
range,
`For security, we recommend using the HTTPS module (${process.title})`,
DiagnosticSeverity.Warning
);
}

return;
} else {
return;
}
})
.filter(v => v);

connection.sendDiagnostics({
uri: document.uri,
version: document.version,
diagnostics: diagnostics
diagnostics: invalidImportModulesDiagnostics.concat(
NotHTTPSImportModulesDiagnostics
)
});
}

Expand Down

0 comments on commit 72d9db3

Please sign in to comment.