CI-Police-adding-rules
Intro
CI Police is a FED tool that allows users (us) to enforce rules on builds (modules' builds).
This solution should eventually replace our current solution - relying on the modules to configure a linter that will enforce our rules.
The basic idea is the same, we're still running a linter, but now it is running on the builds without the need to configure it on old or new modules.
NOTE: the rule is being run in two steps, running the rule and later reading the result, this is a limitation of the infra and is somewhat limiting rules' creation.
The environment
Repo: mobile-ci-police-rules
Main logic file: eslintConfig
Our deprecations folder: uilib-deprecations
Noteworthy files:
- mobile-ci-police-utils - the
isWixUILibUserfunction - rules (definitions) - here we'll add new types of rules such as typography \ functions deprecations
Actual rules are located here, to create a new rule you can: use yarn create-rule (but it'll be created in the root folder and not the correct place) or simply copy an existing rule and modify the following:
- Change folder name
package.json->name(cannot have a.in the name)package.json->wix->artifact->artifactId(cannot have a.in the id)- Modify
src/index- this should be relatively simple since the heavy lifting is done in oureslint-rules
Most rules should ignore non@wix/wix-react-native-ui-libusers (using theisWixUILibUsermethod). - Modify one or more of the above infra rules as needed
- Add tests as needed (might be in the infra folders)
- Verify by running
yarn-->yw <rule_name> build-->yarn test(testing everything can take a while, you can run only the tests you've added)
Enforcement
The rules (all the rules, including FED's) can be viewed in the CI Police Station.
If you go to the developer section you'll be able to see the some details on all the rules and if you're the owner of a rule (decided by ownership tag, ours is wix-react-native-ui-lib) you'll see them under My Rules and be able to edit them.
Add Rule
After merging the rule into the CI-Police library, we need to add the rule to the CI Police Station.
In the developers section we can find My Rules and + button.
Click on the + button and register your new rule:
Rule Typeshould beStandardRule Nameshould be the name of the rule from thepackage.jsonfile, without the@wix/ci-police-rule-prefix.Ownership tagshould be set towix-react-native-ui-libSupport channelis#mads-support.
Rule stages
development - testing your rule, make sure to remove filters and verify that there are no unexpected DISABLED (crash?) or IGNORE rules
Once you've finished testing and you think you're rule is ready, request approval (make sure you have documented your rule, there are no crashes and so on)
NOTE: an IGNORE without an explanation (hover over it) is probably ok (PASS) and is a result of running on the master branch which does not run the rule properly
promoted - the rule is running but does not break builds
enforced - the rule is running and is breaking builds
Adding a new rules to the eslint library
We are still using our own (public) lint rules, which we are still maintaining, but now they are running in CI Police.
Most rules should use the existing rules and adding new rules should be (extremely) rare.
Component prop deprecation
When starting a prop deprecation process we should add the component and the prop to the end of the json in the uilib-deprecate-component-prop file.
When adding a prop to this file, you should add the release version of this deprecation to the top of the file const UILIB_VERSION_5_XX_0 = '[UILIB 5.XX.0]'; and add this version in the deprecation message.