-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: TypeScript config parser #847
Conversation
|
||
## Events emitted | ||
|
||
This `parser` emits the following events the events: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the following events:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also explain how they can import
them in their project.
* `resource`: the parsed resource. | ||
* `errors`: all the errors that the schama validator returns. | ||
|
||
* `notfound::typescript-config`. This event doesn't containt anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe explain this event is sent at the end if no TypeScript configuration has been found?
wich contains the folloing information: | ||
|
||
* `resource`: the parsed resource. | ||
* `error`: the error emited parsing the configuration file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does an error look like?
LF = 'LF' | ||
} | ||
|
||
export type TypeScriptPaths = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing jsdoc in a few exports in this file
} | ||
|
||
private async validateSchema(config: TypeScriptConfig, resource: string) { | ||
// ajv is lower case to be able to get the types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this comment. Why exactly can't we do:
import * as Ajv from 'ajv';
const x: Ajv.Ajv = new Ajv({});
const invalidSchema = async (fetchEnd: TypeScriptConfigInvalidSchema) => { | ||
const { errors, resource } = fetchEnd; | ||
|
||
debug(`Validating rule typescript-config-is-valid`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
schema is invalid
debug
should already prefix where the message is coming from
@@ -0,0 +1,3 @@ | |||
# 1.0.0 (February 8, 2018) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to have this as a fixture. Put other content that explains the purpose of this file.
const ruleName = getRuleName(__dirname); | ||
|
||
/* | ||
* You should test for cases where the rule passes and doesn't. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment
}, | ||
{ | ||
dir: path.join(__dirname, 'fixtures', 'noconfig'), | ||
name: `If there is no config files, it should pass` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no config file
@@ -18,6 +18,7 @@ | |||
* [`html-checker`](../../../../rule-html-checker/README.md) | |||
* [`meta-viewport`](../../../../rule-meta-viewport/README.md) | |||
* [`no-friendly-error-pages`](../../../../rule-no-friendly-error-pages/README.md) | |||
* [`typescript-config-is-valid`](typescript-config-is-valid.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd create a new section Development
for this kind of rules.
Also kind of related webhintio/webhintio.github.io#391
@@ -0,0 +1,42 @@ | |||
# Parser typescript-config (`@sonarwhal/parser-typescript-config`) | |||
|
|||
The `typescript-config` parser allow the user analyze the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow_s_ the user to analyze
@@ -0,0 +1,473 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not exactly a copy/past of the original one. I'm adding a couple of "additionalProperties": false.
import { Sonarwhal } from 'sonarwhal/dist/src/lib/sonarwhal'; | ||
import { loadJSONFile } from 'sonarwhal/dist/src/lib/utils/misc'; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra empty line.
public constructor(sonarwhal: Sonarwhal) { | ||
super(sonarwhal); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra empty line.
@@ -0,0 +1,201 @@ | |||
Apache License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for it.
@@ -0,0 +1,56 @@ | |||
# typescript-config-is-valid (`typescript-config-is-valid`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should contain the package name :@sonarwhal/typescript-config-is-valid
.
|
||
```json | ||
{ | ||
"parsers": ["typescript-config"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should provide more context here. e.g.:
{
...
"parsers": ["typescript-config"],
"rules": {
...
},
...
}
"private": true, | ||
"repository": "sonarwhal/sonarwhal", | ||
"scripts": { | ||
"build": "npm run clean && npm-run-all build:*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
"extends": "../../../../.nycrc" | ||
}, | ||
"peerDependencies": { | ||
"sonarwhal": "^0.27.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonarwhal/parser-typescript-config
?
400ccda
to
b26f278
Compare
@alrra done! |
0fec684
to
a0573d2
Compare
b26f278
to
5e8841e
Compare
bd5402c
to
7aeb1f0
Compare
@molant done! |
5e8841e
to
32d12cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarvaje Can you also add a .npmrc
file? Thanks!
"clean": "rimraf dist", | ||
"lint": "npm-run-all lint:*", | ||
"lint:js": "eslint . --cache --ext js --ext md --ext ts --ignore-path ../../.eslintignore --report-unused-disable-directives", | ||
"lint:md": "markdownlint *.md", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lint:md": "markdownlint --ignore CHANGELOG.md *.md",
@alrra done! |
f832056
to
a80c20e
Compare
To use it you will have to install it via `npm`: | ||
|
||
```bash | ||
npm install @sonarwhal/parser-typescript-config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--save-dev
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. you have to install the package to use the parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to suggesting:
npm install --save-dev @sonarwhal/parser-typescript-config
As in, suggest to users to install it as a dev dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why as a dev dependency? I don't follow you :s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sonarwhal
and related package should be used as part of the development process, so they should be used as dev dependencies not dependencies.
Doing
npm install @sonarwhal/parser-typescript-config
will install @sonarwhal/parser-typescript-config
as a dependency not as a devDependency, because npm install @sonarwhal/parser-typescript-config
is the same as npm install --save @sonarwhal/parser-typescript-config
From https://docs.npmjs.com/cli/install#description:
By default, npm install will install all modules listed as dependencies in package.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the confusion is because I missed -g
but if you have sonarwhal installed globally and you want to use this parser, you have to install the package normally, not as a dev dependency.
which contains the following information: | ||
|
||
* `resource`: the parsed resource. | ||
* `config`: an object with a valid the configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the
.
* `config`: an object with a valid the configuration. | ||
|
||
* `invalid-json::typescript-config`, of type `TypeScriptConfigInvalid` | ||
wich contains the folloing information: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following
* `error`: the error emited parsing the configuration file. | ||
|
||
* `invalid-schema::typescript-config`, of type `TypeScriptConfigInvalidSchema` | ||
wich contains the following information: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which
@alrra done! |
9d3b614
to
b0d880e
Compare
New: `typescript-config-is-valid` rule.
0125603
to
e25f451
Compare
|
||
This parser detect if a TypeScript configuration file is present in your | ||
project, checking the name of the file (i.e. `tsconfig.json`, | ||
`tsconfig.developement.json`). This parser just read your config file and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...sconfig.developement.json`), reads it, and validates the content. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parser detects if a
@@ -0,0 +1,58 @@ | |||
# typescript-config/is-valid (`@sonarwhal/rule-typescript-config`) | |||
|
|||
`typescript-config/is-valid` warns again providing an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
against
@@ -0,0 +1 @@ | |||
module.exports = { javascript: require('./typescript-config') }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant typescript-config
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
New:
typescript-config-is-valid
rule.Pull request checklist
Make sure you:
For non-trivial changes, please make sure you also:
Short description of the change(s)