Skip to content
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

Closed
wants to merge 19 commits into from

Conversation

sarvaje
Copy link
Contributor

@sarvaje sarvaje commented Mar 1, 2018

New: typescript-config-is-valid rule.

Pull request checklist

Make sure you:

For non-trivial changes, please make sure you also:

  • Added/Updated related documentation.
  • Added/Updated related tests.

Short description of the change(s)


## Events emitted

This `parser` emits the following events the events:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the following events:

Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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 = {
Copy link
Member

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.
Copy link
Member

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`);
Copy link
Member

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)
Copy link
Member

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.
Copy link
Member

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`
Copy link
Member

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)
Copy link
Member

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

@molant molant mentioned this pull request Mar 2, 2018
4 tasks
@@ -0,0 +1,42 @@
# Parser typescript-config (`@sonarwhal/parser-typescript-config`)

The `typescript-config` parser allow the user analyze the
Copy link
Contributor

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 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarvaje, @molant l presume the release script should also update this file?

Copy link
Contributor Author

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';


Copy link
Contributor

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);


Copy link
Contributor

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
Copy link
Contributor

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`)
Copy link
Contributor

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.

@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 2, 2018

@molant @alrra done!!

@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 3, 2018

@molant @alrra I have updated the way we run the test for the local connector. Now there is a new method testLocalRule in the rule-runner .


```json
{
"parsers": ["typescript-config"]
Copy link
Contributor

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:*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonarwhal/parser-typescript-config ?

@sarvaje sarvaje force-pushed the parser-typescript branch from 400ccda to b26f278 Compare March 5, 2018 17:08
@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 5, 2018

@alrra done!

@alrra alrra force-pushed the master branch 3 times, most recently from 0fec684 to a0573d2 Compare March 6, 2018 10:00
@sarvaje sarvaje force-pushed the parser-typescript branch from b26f278 to 5e8841e Compare March 6, 2018 19:38
@alrra alrra force-pushed the master branch 2 times, most recently from bd5402c to 7aeb1f0 Compare March 6, 2018 20:38
@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 6, 2018

@molant done!

@sarvaje sarvaje force-pushed the parser-typescript branch from 5e8841e to 32d12cc Compare March 6, 2018 23:13
Copy link
Contributor

@alrra alrra left a 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",
Copy link
Contributor

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",

@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 7, 2018

@alrra done!

@sarvaje sarvaje force-pushed the parser-typescript branch 2 times, most recently from f832056 to a80c20e Compare March 7, 2018 22:29
To use it you will have to install it via `npm`:

```bash
npm install @sonarwhal/parser-typescript-config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--save-dev ?

Copy link
Contributor Author

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.

Copy link
Contributor

@alrra alrra Mar 7, 2018

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.

Copy link
Contributor Author

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

Copy link
Contributor

@alrra alrra Mar 7, 2018

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which

@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 8, 2018

@alrra done!

@sarvaje sarvaje force-pushed the parser-typescript branch 2 times, most recently from 9d3b614 to b0d880e Compare March 8, 2018 22:14
@sarvaje sarvaje force-pushed the parser-typescript branch from 0125603 to e25f451 Compare March 8, 2018 23:04

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
Copy link
Contributor

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. ?

Copy link
Member

@molant molant Mar 8, 2018

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
Copy link
Contributor

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') };
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@sarvaje
Copy link
Contributor Author

sarvaje commented Mar 8, 2018

@molant, @alrra, @qzhou1607 done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants