Skip to content

Commit

Permalink
feat: enable TypeScript by default
Browse files Browse the repository at this point in the history
Enable TypeScript in the following UIs:

* CLI
* Vim plugins
  * ALE
  * CoC (untested)
  * nvim-lspconfig
* Visual Studio Code extension
* Web demo

Also document how to enable TypeScript in the following UIs:

* Emacs plugins
  * Flymake
* Sublime Text

The following UIs aren't working with TypeScript yet:

* Emacs plugins
  * Eglot #1146
  * Flycheck #1148
  * LSP Mode #1147
* Kate #1149
  • Loading branch information
strager committed Jan 1, 2024
1 parent b80b256 commit a76bf1c
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 210 deletions.
10 changes: 9 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ Semantic Versioning.

## Unreleased

### Added

* TypeScript is now supported by default in the CLI and in all editor plugins.
* Exception: [Emacs with Eglot](https://github.com/quick-lint/quick-lint-js/issues/1146)
* Exception: [Emacs with Flycheck](https://github.com/quick-lint/quick-lint-js/issues/1148)
* Exception: [Emacs with LSP Mode](https://github.com/quick-lint/quick-lint-js/issues/1147)
* Exception: [Kate](https://github.com/quick-lint/quick-lint-js/issues/1149)

### Fixed

* TypeScript support (still experimental):
* TypeScript support:
* Assigning to a variable with the same name as an `import`ed type no longer
falsely reports [E0185][] ("assignment to imported variable").
* Interface index signature variables can now be named contextual keywords
Expand Down
22 changes: 6 additions & 16 deletions docs/cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,15 @@ Added in quick-lint-js version 0.3.0.
* *default* (default): infer the _languageid_ from the file's extension:
** *.js*: *javascript-jsx*
** *.jsx*: *javascript-jsx*
** (anything else): *javascript-jsx*
* *experimental-default*: infer the _languageid_ from the file's extension (EXPERIMENTAL; subject to change in future versions of quick-lint-js):
** *.js*: *javascript-jsx*
** *.jsx*: *javascript-jsx*
** *.d.ts*: *experimental-typescript-definition*
** *.ts*: *experimental-typescript*
** *.tsx*: *experimental-typescript-jsx*
** *.d.ts*: *typescript-definition*
** *.ts*: *typescript*
** *.tsx*: *typescript-jsx*
** (anything else): *javascript-jsx*
* *javascript*: the latest ECMAScript standard with proposed features.
* *javascript-jsx*: like *javascript* but with JSX (React) extensions.
* *experimental-typescript*: the latest TypeScript version.
(EXPERIMENTAL.
Subject to change in future versions of quick-lint-js.)
* *experimental-typescript-definition*: the latest TypeScript version (.d.ts file).
(EXPERIMENTAL.
Subject to change in future versions of quick-lint-js.)
* *experimental-typescript-jsx*: like *experimental-typescript* but with JSX (React) extensions.
(EXPERIMENTAL.
Subject to change in future versions of quick-lint-js.)
* *typescript*: the latest TypeScript version.
* *typescript-definition*: the latest TypeScript version (.d.ts file).
* *typescript-jsx*: like *typescript* but with JSX (React) extensions.

If *--language* is given twice, then the _languageid_ for the first *--language* option applies only to the input files between the two *--language* options, and the _languageid_ for the second *--language* option apples only to the input files after the second *--language* option.
See the <<Example>> section for an example.
Expand Down
8 changes: 4 additions & 4 deletions docs/lsp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ command-line option
|`javascript-jsx`

|`tsx`
|`experimental-typescript-jsx`
|`typescript-jsx`

|`typescript`
|See below

|`typescriptsource`
|`experimental-typescript`
|`typescript`

|`typescriptdefinition`
|`experimental-typescript-definition`
|`typescript-definition`

|`typescriptreact`
|`experimental-typescript-jsx`
|`typescript-jsx`

|(any)
|See below
Expand Down
8 changes: 0 additions & 8 deletions plugin/emacs/flymake-quicklintjs.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
:group 'flymake-quicklintjs
:type '(repeat string))

(defcustom flymake-quicklintjs-experimental-typescript nil
"Enable experimental TypeScript support (EXPERIMENTAL; subject to change in future versions of quick-lint-js)."
:group 'flymake-quicklintjs
:type '(boolean))

(defvar-local flymake-quicklintjs--proc nil
"Internal variable for `flymake-quicklintjs'")

Expand Down Expand Up @@ -81,9 +76,6 @@ REPORT-FN is Flymake's callback."
(if file
`("--stdin-path" ,file)
()))
,@(if flymake-quicklintjs-experimental-typescript
`("--language=experimental-default")
())
"--stdin" "--output-format=emacs-lisp"
,@flymake-quicklintjs-args)
:sentinel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
" https://github.com/dense-analysis/ale

call quick_lint_js_ale#init_variables()

if g:ale_javascript_quick_lint_js_experimental_typescript
call quick_lint_js_ale#define_linter('typescript')
endif
call quick_lint_js_ale#define_linter('typescript')

" quick-lint-js finds bugs in JavaScript programs.
" Copyright (C) 2020 Matthew "strager" Glazar
Expand Down
2 changes: 0 additions & 2 deletions plugin/vim/quick-lint-js.vim/autoload/quick_lint_js_ale.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ function! quick_lint_js_ale#init_variables() abort
call ale#Set('javascript_quick_lint_js_use_global', get(g:, 'ale_use_global_executables', v:true))

call ale#Set('javascript_quick_lint_js_tracing_directory', '')

call ale#Set('javascript_quick_lint_js_experimental_typescript', v:false)
endfunction

function! quick_lint_js_ale#define_linter(filetype) abort
Expand Down
34 changes: 7 additions & 27 deletions plugin/vim/quick-lint-js.vim/doc/quick-lint-js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ If you enable |g:ale_linters_explicit|, add the following code to
let b:ale_linters = ['quick-lint-js']
To lint TypeScript as well, enable
|g:ale_javascript_quick_lint_js_experimental_typescript| and also add the
following code to `~/.vim/ftplugin/typescript.vim` (UNIX) or
To lint TypeScript as well, also add the following code to
`~/.vim/ftplugin/typescript.vim` (UNIX) or
`~/vimfiles/ftplugin/typescript.vim` (Windows):

let b:ale_linters = ['quick-lint-js']
Expand Down Expand Up @@ -138,12 +137,9 @@ files.
g:ale_javascript_quick_lint_js_experimental_typescript
*g:ale_javascript_quick_lint_js_experimental_typescript*
*b:ale_javascript_quick_lint_js_experimental_typescript*
Type: |Boolean|
Default: `v:false`

Set this variable to `v:true` to lint TypeScript and TypeScript JSX files, not
just JavaScript and JSX files. (EXPERIMENTAL. Subject to change in future
versions of quick-lint-js.) (Introduced in quick-lint-js version 2.11.0.)
This variable is unused. It was removed in quick-lint-js version
3.0.0.

==============================================================================
3.2. Configuring for coc.nvim *quick-lint-js-configure-coc-nvim*
Expand Down Expand Up @@ -182,13 +178,9 @@ snippet into your |coc-configuration| then tweaking it according to
g:coc_quick_lint_js_experimental_typescript
*g:coc_quick_lint_js_experimental_typescript*
*b:coc_quick_lint_js_experimental_typescript*
Type: |Boolean|
Default: `v:false`

Set this variable to `v:true` to lint TypeScript and TypeScript JSX files, not
just JavaScript and JSX files. Must be set before loading the quick-lint-js
Vim plugin. (EXPERIMENTAL. Subject to change in future versions of
quick-lint-js.) (Introduced in quick-lint-js version 2.11.0.)
This variable is unused. It was removed in quick-lint-js version
3.0.0.

==============================================================================
3.3. Configuring for nvim-lspconfig *quick-lint-js-configure-nvim-lspconfig*
Expand Down Expand Up @@ -235,23 +227,11 @@ Set this option to a table of strings containing the operating system command
for quick-lint-js. You must include the `"--lsp-server"` option.

filetypes *quick-lint-js-configure-nvim-lspconfig-filetypes*
Default: `{"javascript", "javascriptreact"}`
Default: `{"javascript", "javascriptreact", "typescript", "typescriptreact"}`

Set this option to a table of strings to enable quick-lint-js for different
|filetype|s.

To lint TypeScript and TypeScript JSX files, not just JavaScript and JSX
files, add `"typescript"` and `"typescriptreact"` to `filetypes`
(EXPERIMENTAL. Subject to change in future versions of quick-lint-js.)
(Introduced in quick-lint-js version 2.11.0.): >
require('lspconfig/quick_lint_js').setup {
filetypes = {
"javascript", "javascriptreact",
"typescript", "typescriptreact",
},
}
settings.quick-lint-js.tracing-directory
*quick-lint-js-configure-nvim-lspconfig-tracing-directory*
Type: |String|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local quick_lint_js_config = {
-- Keep these in sync with
-- plugin/vim/quick-lint-js.vim/doc/quick-lint-js.txt.
cmd = {"quick-lint-js", "--lsp-server"},
filetypes = {"javascript", "javascriptreact"},
filetypes = {"javascript", "javascriptreact", "typescript", "typescriptreact"},
root_dir = function(fname)
local root = lspconfig_util.path.dirname(fname)
lspconfig_util.path.traverse_parents(fname, function(dir, _path)
Expand Down
8 changes: 1 addition & 7 deletions plugin/vim/quick-lint-js.vim/plugin/quick-lint-js.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
" Register quick-lint-js with coc.nvim (Conquer of Completion).
" https://github.com/neoclide/coc.nvim

let s:enable_typescript = get(g:, 'coc_quick_lint_js_experimental_typescript', v:false)

let s:filetypes = ['javascript', 'javascriptreact', 'json']
if s:enable_typescript
call add(s:filetypes, 'typescript')
call add(s:filetypes, 'typescriptreact')
endif
let s:filetypes = ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'json']

try
call coc#config('languageserver', {
Expand Down
6 changes: 0 additions & 6 deletions plugin/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
"type": "object",
"title": "quick-lint-js",
"properties": {
"quick-lint-js.experimental-typescript": {
"scope": "window",
"type": "boolean",
"default": false,
"description": "Lint TypeScript and TypeScript JSX files, not just JavaScript and JSX files. (Requires restart.) (EXPERIMENTAL. Subject to change in future versions of quick-lint-js.)"
},
"quick-lint-js.logging": {
"scope": "window",
"type": "string",
Expand Down
12 changes: 1 addition & 11 deletions plugin/vscode/quick-lint-js/vscode/qljs-workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ class Extension_Configuration {
: config_ref_(::Napi::Persistent(
vscode.get_configuration(env, "quick-lint-js"))) {}

bool get_experimental_typescript(::Napi::Env env) {
::Napi::Value value = this->get(env, "experimental-typescript");
if (!value.IsBoolean()) {
return false;
}
return value.As<::Napi::Boolean>().Value();
}

Logging_Value get_logging(::Napi::Env env) {
::Napi::Value value = this->get(env, "logging");
if (!value.IsString()) {
Expand Down Expand Up @@ -308,13 +300,11 @@ QLJS_Document_Base* QLJS_Workspace::maybe_create_document(
if (to_string(vscode_document_uri.Get("scheme")) == "file") {
file_path = to_string(vscode_document_uri.Get("fsPath"));
}
bool allow_typescript = Extension_Configuration(env, this->vscode_)
.get_experimental_typescript(env);

QLJS_Document_Base* doc;
if (const VSCode_Language* lang = VSCode_Language::find(
vscode_doc.language_id(), to_string8_view(vscode_doc.uri_string()),
/*allow_typescript=*/allow_typescript)) {
/*allow_typescript=*/true)) {
doc = new QLJS_Lintable_Document(vscode_doc, file_path, lang->lint_options);
} else if (file_path.has_value() &&
this->config_loader_.is_config_file_path(*file_path)) {
Expand Down
37 changes: 2 additions & 35 deletions plugin/vscode/test/vscode-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,6 @@ tests = {
});
},

"parser does not check TypeScript files by default": async ({
addCleanup,
}) => {
for (let extension of [".ts", ".tsx"]) {
let scratchDirectory = makeScratchDirectory({ addCleanup });
let helloFilePath = path.join(scratchDirectory, `hello${extension}`);
fs.writeFileSync(helloFilePath, "this is a bug");
let helloURI = vscode.Uri.file(helloFilePath);

await loadExtensionAsync({ addCleanup });
let helloDocument = await vscode.workspace.openTextDocument(helloURI);
let helloEditor = await vscode.window.showTextDocument(helloDocument);

// Wait for possible linting to take effect.
await sleepAsync(100);
await waitUntilNoDiagnosticsAsync(helloURI);
}
},

"parser checks TypeScript files if opted in": async ({ addCleanup }) => {
let scratchDirectory = makeScratchDirectory({ addCleanup });
let helloFilePath = path.join(scratchDirectory, "hello.ts");
Expand All @@ -242,13 +223,6 @@ tests = {
let helloURI = vscode.Uri.file(helloFilePath);

await loadExtensionAsync({ addCleanup });
await vscode.workspace
.getConfiguration("quick-lint-js")
.update(
"experimental-typescript",
true,
vscode.ConfigurationTarget.Workspace
);
let helloDocument = await vscode.workspace.openTextDocument(helloURI);
let helloEditor = await vscode.window.showTextDocument(helloDocument);

Expand All @@ -263,7 +237,7 @@ tests = {
});
},

"parser checks TypeScript JSX files if opted in": async ({ addCleanup }) => {
"parser checks TypeScript JSX files": async ({ addCleanup }) => {
let scratchDirectory = makeScratchDirectory({ addCleanup });
let helloFilePath = path.join(scratchDirectory, "hello.tsx");
fs.writeFileSync(
Expand All @@ -273,13 +247,6 @@ tests = {
let helloURI = vscode.Uri.file(helloFilePath);

await loadExtensionAsync({ addCleanup });
await vscode.workspace
.getConfiguration("quick-lint-js")
.update(
"experimental-typescript",
true,
vscode.ConfigurationTarget.Workspace
);
let helloDocument = await vscode.workspace.openTextDocument(helloURI);
let helloEditor = await vscode.window.showTextDocument(helloDocument);

Expand Down Expand Up @@ -1568,7 +1535,7 @@ async function pollAsync(callback) {
}

async function resetConfigurationAsync() {
for (let setting of ["experimental-typescript", "logging"]) {
for (let setting of ["logging"]) {
await vscode.workspace
.getConfiguration("quick-lint-js")
.update(setting, undefined, vscode.ConfigurationTarget.Workspace);
Expand Down
10 changes: 3 additions & 7 deletions src/quick-lint-js/cli/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ Options parse_options(int argc, char** argv, Monotonic_Allocator* allocator) {
unused_language_option = arg_value;
if (arg_value == "default"sv) {
language = Raw_Input_File_Language::default_;
} else if (arg_value == "experimental-default"sv) {
language = Raw_Input_File_Language::experimental_default;
} else if (arg_value == "javascript"sv) {
language = Raw_Input_File_Language::javascript;
} else if (arg_value == "javascript-jsx"sv) {
language = Raw_Input_File_Language::javascript_jsx;
} else if (arg_value == "experimental-typescript"sv) {
} else if (arg_value == "typescript"sv) {
language = Raw_Input_File_Language::typescript;
} else if (arg_value == "experimental-typescript-definition"sv) {
} else if (arg_value == "typescript-definition"sv) {
language = Raw_Input_File_Language::typescript_definition;
} else if (arg_value == "experimental-typescript-jsx"sv) {
} else if (arg_value == "typescript-jsx"sv) {
language = Raw_Input_File_Language::typescript_jsx;
} else {
error_unrecognized_options.emplace_back(arg_value);
Expand Down Expand Up @@ -324,8 +322,6 @@ Resolved_Input_File_Language get_language(const File_To_Lint& file,
Resolved_Input_File_Language get_language(const char* file,
Raw_Input_File_Language language) {
if (language == Raw_Input_File_Language::default_) {
return Resolved_Input_File_Language::javascript_jsx;
} else if (language == Raw_Input_File_Language::experimental_default) {
Path_Classification classification = classify_path(file);
if (classification.typescript_jsx) {
return Resolved_Input_File_Language::typescript_jsx;
Expand Down
3 changes: 0 additions & 3 deletions src/quick-lint-js/cli/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ enum class Output_Format {
enum class Raw_Input_File_Language : unsigned char {
// Explicit (--language=default) or implicit (no --language).
default_,
// Explicit --language=experimental-default.
// TODO(#690): Make experimental_default the default and delete default_.
experimental_default,

javascript,
javascript_jsx,
Expand Down
Loading

0 comments on commit a76bf1c

Please sign in to comment.