Supported syntaxes:
AdGuard | uBlock Origin | AdBlock | Adblock Plus
Table of Contents:
This extension adds support for AdGuard, uBlock Origin and Adblock Plus syntaxes to Visual Studio Code, so you can write adblock rules in a convenient way. It also provides a linter to check your rules for errors.
We recommend using this extension if you are working with adblock rules.
You can easily install the update from the Visual Studio Marketplace or the Open VSX Registry:
Here is a screenshot of the extension in action:
GitHub Linguist support is also available, so you can highlight your adblock rules in GitHub repositories. See GitHub Linguist support for more details. Quick example:
! This is an example rule
example.org##.banner
||example.net/script.js$script,third-party,domain=example.com
In this section we will describe the main features of this extension.
Syntax highlighting is available for AdGuard, uBlock Origin and Adblock Plus syntaxes. Nowadays it is unimaginable to work with code without highlighting, which helps you to distinguish different parts of the code and makes it easier to read.
We integrated AGLint into this extension, that makes it able to check your rules for various issues, such as invalid syntax, invalid domains, invalid / incompatible CSS selectors, unknown / incompatible scriptlets, bad practices, etc. For more information about AGLint, please refer to its repository.
AGLint integration is done in the following way:
- Extension will search local AGLint installation (if it is installed) and use it for linting. First, it will search for local installation in the current workspace, and if it is not found, it will search for a global installation. This is an ideal behavior, because if you have a local installation, it guarantees that you will use the same version of AGLint, and the results will be the same.
- If the extension doesn't find any installation, it will use the bundled version of AGLint, which is included in the extension itself. Usually, it is the latest version of AGLint. The advantage of this approach is that you don't need to install AGLint manually, and you can start using the extension immediately after installation.
Warning
Please note that the linter is under active development, so it may not work properly for some rules. If you find any issues, please report them here. We look forward to your feedback, your help is very important to us!
This extension provides the following configuration options:
Option | Description | Default value | Possible values |
---|---|---|---|
adblock.enableAglint |
Enable or disable AGLint integration. If disabled, only syntax highlighting and other language features will be available. | true |
true , false |
adblock.useExternalAglintPackages |
If enabled, extension will search for AGLint installations in the system. If disabled, extension will use its own AGLint installation, which is included in the extension (integrated AGLint bundle). If you have AGLint installed in your system / project, it is recommended to enable this option in order to provide consistent results. | true |
true , false |
adblock.packageManager |
Package manager to use for searching global AGLint installations. Set it to your preferred package manager. | npm |
npm , yarn , pnpm |
GitHub supports adblock syntax officially via the Linguist library. Our extension provides a
TMLanguage file, which is used by Linguist to highlight adblock rules (VSCode highlight also based on
this file). This means that if you have a repository with adblock rules, GitHub can highlight your .txt
files, if the
following conditions are met:
- If a
*.txt
file begins with an adblock agent (such as[Adblock Plus 2.0]
,[AdGuard]
,[uBlock Origin]
,[Adblock Plus 2.0; AdGuard]
, etc.), then it will be highlighted as an adblock file automatically. You can find the detection heuristics here. - In any other cases, you can override the language classification by adding the following lines to
.gitattributes
file:You can find more information about overriding language classification here.# Override classification for *.txt files, so they are highlighted as adblock files. # - This example will match all *.txt files in the repository, but you can # customize path(s) to match only specific files, such as /filters/*.txt # or /filters/*.adblock. See https://git-scm.com/docs/gitattributes for more details. # - By default, Adblock language doesn't show up in the repository's language statistics, # but adding linguist-detectable will resolve this, so it is recommended to add it. *.txt linguist-language=AdBlock linguist-detectable
In addition, adblock code blocks can be inserted in markdown files and comments according to the following pattern:
```adblock ! Example rule example.org##.banner ```
will be rendered as:
! Example rule
example.org##.banner
If you have any questions or ideas for new features, please open an issue or a discussion. We will be happy to discuss it with you.
If you found a bug or have a feature request, please report it here. Please make sure to include as much information as possible, including screenshots or example rules.
Please note that the highlighter issues on GitHub will not be fixed immediately when we update the TMLanguage in this repository. GitHub's highlighter is only updated after Linguist releases. This process happens roughly every quarter. Before release, Linguist maintainers will update all integrated TMLanguage to the latest version. You can find more information about Linguist's release process here.
If you want to contribute to this project, please read the CONTRIBUTING file.
This extension is licensed under the MIT License. See the LICENSE file for details.
Here are some useful links to help you write adblock rules. This list is not exhaustive, so if you know any other useful resources, please let us know.
- Syntax documentation:
- Extended CSS documentation:
- Scriptlets:
- Third party libraries:
- AdGuard's compatibility table