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

Add lowercase directives #283

Merged
merged 11 commits into from
Jan 22, 2024

Conversation

richardm90
Copy link
Contributor

Changes

There is a linter rule for uppercase directives but not for lowercase directives, I like my directives to be in lowercase, so I've added a new LowercaseDirectives rule.

Whilst making this change I also corrected a couple of issues.

  • Fix IncorrectVariableCase when definition exists in copybook, only noticed when using the Format Document option
  • Fix Quick Fix comment for RequireBlankSpecial
  • Added tests for IncorrectVariableCase, UppercaseDirectives, LowercaseDirectives

Questions/Points

  • Would it be better to have a single rule for the directive case such as DirectivesCase: ['upper', lower']? This would deprecate the existing UppercaseDirectives rule.
  • Is there a way to actually run Quick Fixes as part of unit tests? One of the fixes I implemented only occurred when the Format Document option was run.
  • I'll update the docs once I know the pull request is acceptable.
  • I initially tried using npm run test to run the test suite but this failed with a module not found error. I'm pretty sure this is because the typescript needs to be compiled before the tests are run but I couldn't work out how this be done so used the 'Debug Tests' from the VS Code debugger instead.

Checklist

  • have tested my change
  • updated relevant documentation
  • Remove any/all console.logs I added
  • eslint is not complaining
  • have added myself to the contributors' list in the README

@worksofliam worksofliam self-assigned this Dec 28, 2023
@worksofliam
Copy link
Contributor

worksofliam commented Jan 12, 2024

Would it be better to have a single rule for the directive case such as DirectivesCase: ['upper', lower']? This would deprecate the existing UppercaseDirectives rule.

I absolutely think is the way to do (DirectivesCase ✅) it instead of having two separate rules (UppercaseDirectives, LowercaseDirectives 👎). Don't remove UppercaseDirectives from the schema definition (rpglint.json), but instead mark it as deprecated: true.


Is there a way to actually run Quick Fixes as part of unit tests?

Quick Fixes, no, sadly not. But we can test what location of where the fix will take place. See this assert for example:

  assert.deepStrictEqual(errors[0], {
    offset: { position: 194, end: 202 },
    type: `IncorrectVariableCase`,
    newValue: `localVar`
  });

It's ensuring the ranges in the document, the error type and what the new value will be when the user quick fixes it. This has been a very suitable test so far. I see you are already doing this!


... but this failed with a module not found error.

This is very odd! I am glad the Debug Tests worked from VS Code. I would recommend ensuring you used npm i before running npm run test again. Feel free to share the logs with me.


Let me know what else you need from me for this PR.

schemas/rpglint.json Outdated Show resolved Hide resolved
schemas/rpglint.json Show resolved Hide resolved
@richardm90
Copy link
Contributor Author

@worksofliam, I've just started work on these changes but wanted to clarify one of yours points.

I absolutely think is the way to do (DirectivesCase ✅) it instead of having two separate rules (UppercaseDirectives, LowercaseDirectives 👎). Don't remove UppercaseDirectives from the schema definition (rpglint.json), but instead mark it as deprecated: true.

deprecated isn't a valid property in rpglint.json. Shall I add it anyway? I couldn't find any other examples in the code base except for language/models/tags.js.

@worksofliam
Copy link
Contributor

@richardm90 add for now. This keyword was added back in 2019 to json schema.

https://json-schema.org/draft/2019-09/json-schema-validation#rfc.section.9.3

@richardm90
Copy link
Contributor Author

@richardm90 add for now. This keyword was added back in 2019 to json schema.

https://json-schema.org/draft/2019-09/json-schema-validation#rfc.section.9.3

It looks as though the new JSON schema version isn't fully supported in VS Code yet but I've added the property.

[json] JSONSchema draft 2019-09 support #98724

@richardm90
Copy link
Contributor Author

... but this failed with a module not found error.

This is very odd! I am glad the Debug Tests worked from VS Code. I would recommend ensuring you used npm i before running npm run test again. Feel free to share the logs with me.

I tried npm i but still no joy. This is the output in the terminal. I think it might be something to do with Typescript transpiling.

$ npm run test

> [email protected] test
> tsx tests

(node:29973) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("file%3A///home/richard/git/vscode-rpgle/node_modules/tsx/dist/loader.js", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/modules/cjs/loader:1134
  const err = new Error(message);
              ^

Error: Cannot find module '../parserSetup'
Require stack:
- /home/richard/git/vscode-rpgle/tests/suite/basics.js
- /home/richard/git/vscode-rpgle/tests/suite/index.js
- /home/richard/git/vscode-rpgle/tests/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/richard/git/vscode-rpgle/tests/suite/basics.js:5:34)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/richard/git/vscode-rpgle/tests/suite/basics.js',
    '/home/richard/git/vscode-rpgle/tests/suite/index.js',
    '/home/richard/git/vscode-rpgle/tests/index.js'
  ]
}

Node.js v18.19.0

@worksofliam worksofliam self-assigned this Jan 20, 2024
Copy link
Contributor

@worksofliam worksofliam left a comment

Choose a reason for hiding this comment

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

@richardm90 A great PR! Thanks so much for your work here.

I am going to approve and merge today. One question I have for you: can I expect another PR from you after this that completely removes UppercaseDirectives from the codebase (but perhaps left in rpglint.json schema)?

@worksofliam worksofliam merged commit 40e3c89 into codefori:main Jan 22, 2024
@worksofliam
Copy link
Contributor

@richardm90 Second ask: please update the docs with a PR over there when you can!

@richardm90
Copy link
Contributor Author

@worksofliam Ah OK. I wasn't clear on deprecated stuff. I thought there would be a period of time before the feature was removed from the codebase. I'm happy to strip it out of the codebase though and presumably remove if from the docs as well?

@richardm90 richardm90 deleted the add_lowercase_directives branch January 22, 2024 19:00
@worksofliam
Copy link
Contributor

@richardm90 leave it in the docs for a while but leave a note that it's deprecated!

@richardm90 richardm90 mentioned this pull request Feb 4, 2024
6 tasks
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.

2 participants